Category Archives: Entity framework

How can I get Id of inserted entity in Entity framework?

It is pretty easy. If you are using DB generated Ids (like IDENTITY in MS SQL) you just need to add entity to ObjectSet and SaveChanges on related ObjectContext. Id will be automatically filled for you: using (var context = new MyContext()) { context.MyEntities.AddObject(myNewObject); context.SaveChanges(); int id = myNewObject.Id; // Yes it’s here } Entity… Read More »

What is POCO in Entity Framework?

POCOS(Plain old CLR objects) are simply entities of your Domain.Normally when we use entity framework the entities are generated automatically for you.This is great but unfortunately these entities are interspersed with database access functionality which is clearly against the SOC(Separation of concern).POCOS are simple entities without any data access functionality but still gives the capabilities… Read More »