POCO Data updates

Sep 13, 2010 at 9:20 PM



Great article!

I have done some testing with E4 based on your / this project: Lazy loading, getting data based on a complete graph back, but I do have some questions:



        public List<Expense> SelectActive()


            using (ExpenseDataContext ctx = new ExpenseDataContext())


             return ctx.Expenses



              .Where(e => e.IsCompleted == false)







   public Expense UpdateExpense(Expense expense)




   var bc = new ExpenseComponent();

   var expenses = bc.ListActiveExpenses();

   if (expenses.Any())


    var expense = expenses.FirstOrDefault();

    if (expense.ExpenseReviews.Any())


     expense.ExpenseReviews.FirstOrDefault().Remarks = "test " + DateTime.Now.ToLongDateString();





Test code in ExpenseDataAccess.Update:


                var changed = ctx.ObjectStateManager.GetObjectStateEntries(EntityState.Modified);

                var cnt = changed.Count();


Why isn’t the ExpenseReview record updated in the database and if I test the code update in the ExpenseDataAccess I always get a ‘changed count’ of 1 even with NO updates.

All help welcome ;-)




Sep 14, 2010 at 1:40 PM


I am not really a pro in EF but could it be because I have the following code in the constructors of the ExpenseDataContext class?

        public ExpenseDataContext()
            : base("name=ExpenseEntities""ExpenseEntities")  
            this.ContextOptions.LazyLoadingEnabled = false;
            this.ContextOptions.ProxyCreationEnabled = false;


Best Regards,

Serena Yeoh

Sep 14, 2010 at 6:40 PM
Edited Sep 15, 2010 at 10:19 AM

Hi Serena,

I have already disabled LazyLoading ;-) But I have problems with the updates in the child records. Your project is (one of) the best layered examples with EF, but what layer is responsible for the update of the child records. Should we handle the child updates in ExpenseComponent or in the DAC?

Do you have experience with the CTP 'Self Tracking Enities' http://blogs.msdn.com/b/adonet/archive/2009/06/22/feature-ctp-walkthrough-self-tracking-entities-for-the-entity-framework.aspx ? Maybe that's the solution?!

Greetings Jean-Pierre.

Sep 16, 2010 at 4:47 AM

Hi Jean,

I think you have to enable lazy loading. The data layer is responsible for all create, read, update and delete (CRUD) operations. The sample does not contain any self-tracking code. You many need to check with the ADO.NET EF documentation on how to create self-tracking entities with POCO.

Sorry for my limited knowledge in ADO.NET EF. I may consider looking at it when I have the time.

Best Regards,

Feb 23, 2011 at 9:52 PM
SjanPjer wrote:

Your project is (one of) the best layered examples with EF


I'm looking for examples just like that and this one is the only decent one I have found so far. I am looking to expand my knowledge and understanding in order to spice my dev life up a bit ;) I've been stuck on the same projects and technologies for years...

Would you have other examples available for download?


Seb :)