开发者

Entity Framework NoTracking not working

I'm trying to run a no tracking query on my entities so that I can update them outside of the context. However, when the no tracking is not working and I get an exception stating

"The ObjectContext instance has been disposed and can no longer be used for operations that require a connection."

This exception is thrown by a property which in terms of the database model is a foreign key to a separate table, do I need to somehow set notracking for this separate entity as well?

My code is:

    List<EmailQueue> result =开发者_如何学JAVA null;
            using (Entities context = new Entities())
            {

                var emailQueueQuery = context.EmailQueues;
                emailQueueQuery.MergeOption = System.Data.Objects.MergeOption.NoTracking;
                result = emailQueueQuery.Execute(System.Data.Objects.MergeOption.NoTracking).ToList<EmailQueue>();

            }
            return result;


My wild guess is that you have lazy loading turned on?

If you dispose the ObjectContext, then lazy loading can't work.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜