如何统一身份上下文和我的上下文? [英] How can I unify identity context and my context?

查看:69
本文介绍了如何统一身份上下文和我的上下文?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,



我对MVC和EF很新。我创建了MVC项目,并在创建项目时选择了单用户身份验证选项,Visual Studio创建了

Hello,

I am quite new to MVC and EF. I created my MVC project and I selected single user authentication option while creating the project and visual studio has created the

public class ApplicationDbContext: IdentityDbContext<ApplicationUser>

。然后我创建了自己的上下文来处理我的业务。



我的问题是:我可以在一个上下文类中统一这两个上下文类吗?怎么样?所以我可以在一个上下文中执行迁移,而不是为2个类处理它。







谢谢你们全部。



我尝试了什么:



i不知道确切地说该做什么。

. Then I created my own context to handle my business.

My question is: can I unify these 2 context classes in one context classes & how? So I can perform the migration on a single context instead of handles this for 2 classes



Thank You ALL.

What I have tried:

i do not know exactly what to do.

推荐答案

他们希望您创建自己的上下文和类来管理和处理业务逻辑。



想象一下,如果微软发布更新并且从 IdentityDbContext<中更改大部分代码(如果不是全部),将会发生什么。 T> 类型。你能承受这种破坏性的改变吗?因为您现在将所有内容都放在单个文件中,并且可以通过运行时/平台或程序包的更新轻松更改该文件。



我无法处理它们在ASP.NET Core 1.1中对ASP.NET Core 2.0所做的微小更改。我不能,并且看到这是当时发生的事情,不可能的任务:将.NET Core 1.x迁移到2.0 [ ^ ]。



这就是为什么,我建议保留多个上下文,它没有任何损害,对于一个普通的超个人项目,通常有多个上下文,每个上下文处理自己的目的和与数据库的连接。



欢迎您在CodeProject上尝试并分享您的经验,我想了解一下会发生什么! :)
There is a reason why they want you to create your own context and class to manage and handle your business logic.

Just imagine what will happen, if, Microsoft ships an update and that changes most of the code (if not all) from the IdentityDbContext<T> type. Can you afford such a build-breaking change? Because you are now having everything inside a single file, and that file can be easily changed by an update for the runtime/platform or package.

I could not handle the minor changes they made back in ASP.NET Core 1.1 to ASP.NET Core 2.0. I could not, and see this is what happened back then, Mission Impossible: Migrating .NET Core 1.x to 2.0[^].

That is why, I recommend keeping multiple contexts, there is no harm in it and for a normal more-than-personal project, there are usually multiple contexts, each handling its own purpose and connection to databases.

You are welcome to try, and share your experience here on CodeProject, I would like to read what happens! :)


Hi Afzaal,



感谢您的澄清。我只想知道这一点的原因和最佳做法。我将按原样离开并继续练习我的项目。





再次感谢:)
Hi Afzaal,

Thanks for the clarification. I just wanted to know the reason and best practices for this point. I am going to leave it as is and continue practicing on my project.


Thanks Again :)


这篇关于如何统一身份上下文和我的上下文?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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