Is there ANY way to initialize a property in an Entity Framework entity that has a collection?
This is the generated code for an Entity that has a collection:
public partial class MyEntity
{
public MyEntity()
{
this.MySubEntities = new HashSet<MySubEntity>();
}
public bool IsActive {get; set;}
public virtual ICollection<MySubEntity> MySubEntities {get; set;}
}
If I need to make a new MyEntity
that I want to default to IsActive = true
, it cannot be done! (Unless I edit the T4 template.)
Please tell me there is a way to default IsActive = True
without editing the generated file (or the T4).
Note: I have AutoMapper making the entity for me, so new MyEntity {IsActive = true}
will not work.