是否认同Owin需要惰性加载? [英] Does Identity Owin require LazyLoading?

查看:114
本文介绍了是否认同Owin需要惰性加载?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

TL;博士:身份似乎需要惰性加载不能被禁用;这是真的,什么是最干净的解决办法?

tl;dr: Identity seems to require that LazyLoading NOT be disabled; is this true, and what is the cleanest workaround?

我没有使用的EntityFramework 6.0.2,身份的EntityFramework 1.0.0,和身份Owin 1.0.0一个简单的C#ASP.NET MVC 4.5.1-5的Web应用程序的一些基本AB测试,看来,Owin要求偷懒装载未在ApplicationContext的构造函数中禁用。

I did some basic A-B testing on a simple C# ASP.NET 4.5.1 MVC-5 web application using EntityFramework 6.0.2, Identity EntityFramework 1.0.0, and Identity Owin 1.0.0 and it appears that Owin requires that lazy loading is NOT disabled in the ApplicationContext constructor.

要复制的问题,只是使用Visual Studio 2013进行快速MVC应用程序,使用MVC模板,除取消该行默认放弃一切:app.UseGoogleAuthentication();'在App_Start / Startup.Auth.cs。运行应用程序,并使用谷歌登陆,完成它需要你的缩写注册页面并转到帐户/管理。您应该看到在底部谷歌2个按钮。停止应用程序。

To replicate the issue just make a quick MVC app using Visual Studio 2013, use the MVC template, leave everything at the defaults except uncomment the line: 'app.UseGoogleAuthentication();' in App_Start/Startup.Auth.cs. Run the app and use Google to login, complete the abbreviated registration page it takes you to and go to account/manage. You should see 2 buttons for Google at the bottom. Stop the app.

现在去ApplicationContext.cs并改变构造如本code片断:

Now go to ApplicationContext.cs and change the constructor as shown in this code snippet:

public ApplicationContext() : base("DefaultConnection") { } //Works!

public ApplicationContext() : base("DefaultConnection") 
{
    this.Configuration.LazyLoadingEnabled = false;
} //Does not work

重试测试。只有1谷歌按钮应该是可见的。随着LazyLoadingEnabled = false用户角色,登录(POSS还称)不加载。

Retry the test. Only 1 Google button should be visible. With LazyLoadingEnabled = false the User Roles, Logins (poss Claims also) aren't loaded.

我的理论是,这是一个微软的监督/'将来的功能作为身份的EntityFramework和身份Owin都是1.0.0版本。

My theory is that this is a Microsoft oversight/'future feature' as Identity EntityFramework and Identity Owin are both version 1.0.0.

我的问题是,可在测试证实,什么是周围的清洁工作?

My question is, can this test be confirmed, and what is the cleanest work around?

对于我而言,我将只使用.ToList()等方法迫使EagerLoading时,我想使用它。我并不真正需要的惰性加载禁用,它只是为code更安全的方式,如果你想一直使用预先加载。即你错过了一个点,这使它对生产,和你有一个很好的臭虫在某些浏览您通过模型和Model.x.yÿ== NULL和数据库连接已被释放。

For my purposes I will just use .ToList() and other methods for forcing EagerLoading when I want to use it. I don't truly need LazyLoading disabled, it's just a safer way to code if you want to always use eager loading. i.e. you miss one spot, it makes it to production, and you have a nice bug where in some View you are iterating through a Model and for Model.x.y y == null and the database connection has been disposed.

让我们不要陷入身份与其他(更强大的)方法,或者:

Let's not get into Identity vs. other (more robust) methods, or:

using (DatabaseContext) { //Database query } 

或调用每一个方法处理VS让连接被自动处理。这是你必须使用Identity Owin和处置的所有数据库调用尽快的场景。应该有我丢失的东西,或者是身份真的只是不完全正确了。

or calling dispose on every method vs letting the connection be disposed automatically. This is a scenario where you have to use Identity Owin, and dispose of all database calls ASAP. There ought to be something I'm missing, or maybe Identity really is just that incomplete right now.

推荐答案

是的,这是我们有固定的2.0.0版本ALPHA1一个bug。与以前的惰性加载明确禁用,EF不会自动加载相关的用户实体(登录/索赔/角色)

Yes this was a bug we have fixed in the 2.0.0-alpha1 release. With lazyLoading explicitly disabled prior, EF would not load the associated user entities automatically (logins/claims/roles)

这篇关于是否认同Owin需要惰性加载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆