Hey i am trying to work with entity framework using in DB first mode. I have a hierarchy of Enitties that are stored in one table called "DomainEntities".
When i generated a schema using the entity framework i got the correct mappongs that look like this.
Now i wonder what is the way i should perform insert using this model. if i want to insert a new entry with a certain parent do i need to do all this:
[HttpPost]
public ActionResult Create(DomainEntity i_EntityToCreate, int ParentEntityID)
{
using (var db = new CamelotShiftManagementEntities())
{
var parentEntity = db.DomainEntities.Find(ParentEntityID);
i_EntityToCreate.ParentEntity = parentEntity;
i_EntityToCreate.EntityTypeID = 1;
db.DomainEntities.Add(i_EntityToCreate);
db.SaveChanges();
}
return RedirectToAction("Index");
}
is this correct or is there another design i should follow to represent a hierarchy of entities using entity framework ?
