Quantcast
Channel: entityframework Discussions Rss Feed
Viewing all articles
Browse latest Browse all 1793

New Post: EF5 + How to save an entity with its child entities at the same time to the database?

$
0
0

Hi
In entity framework we meet to Tracking changes by entity state , then you add object with all children to the your context , you should have sample below code :
using(MydbEntities context=new MydbEntities())
{
// this line can help you for web business code:
Purchase entity=new Purchase();
entity= /* "your Purchase Entity that filled and have children" */ YourPurchaseEntity ;
context.AddToPurchase( entity);

  context.SaveChanges(); //---end line Of bloack       

}
notice : if you develop Web App cause "Post Back" you should in business class Create New Instance Of Your Context before any CUD operations and Select .
also in Win App , the context managed tracking of any changes on entities and you for Debug , you can check EntityState Of any object in Using Block Code "Context".
and one of best advantages EF that is understand relation between master and Detail Entities When you insert to DB or other Operations , by Transactional worked ,by writing context.SaveChanges();
and after any changes context return any affect to entities in Block code , and EntityState of entities changed.


Viewing all articles
Browse latest Browse all 1793

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>