I have the first EF5 code project that uses the [DatabaseGenerated (DatabaseGeneratedOption.Computed)] attribute. This parameter overrides my settings.
Consider this SQL table:
CREATE TABLE Vehicle ( VehicleId int identity(1,1) not null, Name varchar(100) not null default ('Not Set') )
I use the default SQL construct to set [Name] if it is not installed.
In the code behind, I have a class defined as:
public class Vehicle { ... [DatabaseGenerated(DatabaseGeneratedOption.Computed)] public string ShoulderYN { get; set; } }
When I update an object in code, the default value overrides my new setting.
In the code, I have (pseudo):
vehicle.Name = 'Update Name of Vehicle'; _dbContext.Update(vehicle); _dbContext.SaveChanges();
Expected Result: Vehicle.Name = 'Update Vehicle Name'.
Actual result: Vehicle.Name = 'Not Set'.
Is there a way in EF5 to say "if Vehicle.Name is null / empty, use the value defined in the database? Otherwise, if I set a value in the code, I want to use that value."
Thanks.
Steve
Steve source share