EF problem for entity tracking? RRS feed

  • Question

  • Hello I' ve got this query I recall periodically

            EF.PrintingLaunch result = null;
            var query = Globals.context.PrintingLaunches.Where(p => p.Date > DateTime.Now).OrderBy(p => p.Date).Take(1);
            if (query.ToList().Count == 1)
                result = query.ToList()[0];
            return result;

    The problem is: if data on the underlaying database is modified (a PrintingLaunches table), I still get the data read the first time for the related entity. Is it a tracking problem?
    Guess for a solution?

    Thank you!
    Monday, October 26, 2009 1:37 PM


  • Hi AndreaPi,

    You can set MergeOption.NoTracing to get the newest records and then set the merge option back.

    context.Yourtable.MergeOption = System.Data.Objects.MergeOption.NoTracking;
    context.Stu.MergeOption = System.Data.Objects.MergeOption.AppendOnly;

    Does this work for you? If you have any questions or concerns, please update the thread and we will have a further discussion.



    Best Regards

    Yichun Feng

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marked as answer by Yichun_Feng Monday, November 2, 2009 3:39 AM
    Wednesday, October 28, 2009 5:26 AM