开发者

Entity Framework objectcontext ending prematurely

Hello I am getting the error "ObjectContext instance has been disposed and can no longer be used for operations that require a connection". When I run some methods from a wcf service. All of them use a new context object and most of them run without issue. However this one keeps giving the error above although several methods with similar implementations succeed several lines above in my code:

public CustomAuthentication.WebService.Application GetApplicationByUrl(string url)
        {
            try
            {
                using (AuthenticationEntities2 auth = new AuthenticationEntities2())
                {
                    Application app = auth.Applications.Where(a => a.Url.Contains(url)).FirstOrDefault();

                return app;
            }
        }
        catch (Exception ex)
        {
            throw new FaultException(ex.Message + "\r\n" + ex.StackTrace + "\r\n" + ex.InnerException);
        }
    }

I also initially saw thi开发者_如何学Cs error from vs "The underlying connection was closed: A connection that was expected to be kept alive was closed by the server." So I thought it was an issue serializing objects in my wcf service. So I did some tracing on the service and discovered the error above. So now believe its entity related. Any ideas?


Try to turn off lazy loading on your ObjectContext. Most probably your Application contains navigation properties which trigger lazy loading during serialization.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜