I have below entity with a calculated/computed column:
public EntityA
{
[Key(), Required]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
.....
[DatabaseGenerated(DatabaseGeneratedOption.Computed)]
public virtual string RefId {
get
{
return this.Id.ToString().PadLeft(7, '0');
}
private set
{
}
}
}
RefId is a computed column that depends on the Id value.
After performing commit changes to database with SaveChanges I can check that Id and RefId have been set correctly for the entity I am currently inserting on database, but If I open the database and check RefId column for this entity, I can observe that RefId column has not been set, if figures as NULL. Why? Any ideas?