服务层,模型层和unitOfwork中的MVC5实体框架

时间:2018-08-07 04:59:44

标签: c# entity-framework asp.net-identity service-layer

我想开发一个在不同层具有实体框架的系统:服务层,模型层。而且我正在将MVC5与Microsoft授权模块一起使用,并且已将userId从Guid更改为interger(参考:https://docs.microsoft.com/en-us/aspnet/identity/overview/extensibility/change-primary-key-for-users-in-aspnet-identity)。

我遵循了引用(https://royshow0316.github.io/categories/#Asp.Net%E3%80%80MVC)来分隔不同的层。

不幸的是,它部分起作用。

我面临着一些问题:

  1. 通过“ royshow0316.github.io”中的示例代码,我不知道将CustomUserStore集成到UnitConfig.cs #region Identity。

  2. 如果在ApplicationDbContext中使用的连接字符串是实体框架格式:

    <add name="RegSysEntities" connectionString="metadata=
     res://*/RegSys.csdl|
             res://*/RegSys.ssdl|
             res://*/RegSys.msl;
             provider=System.Data.SqlClient;
             provider connection string=
             &quot;data source={HostName};
             initial catalog=RegSys;
             integrated security=True;
             MultipleActiveResultSets=True;
             App=EntityFramework&quot;" 
             providerName="System.Data.EntityClient" />
    

在登录操作期间抛出异常 The entity type ApplicationUser is not part of the model for the current context.

但是其他模块(例如列表)正常工作。

如果连接字符串正常,例如

    <add name="RegSysDbConnection" 
            connectionString="Data Source={HostName};
                    Initial Catalog=RegSys;Integrated 
                    Security=True;
                    MultipleActiveResultSets=True;
                    Application Name=EntityFramework"
            providerName="System.Data.SqlClient" />

它可以在登录操作中使用,但在列出过程中会引发Follow异常 The entity type AspNetUser is not part of the model for the current context.

几天来我对这些问题感到头疼。请帮忙。

0 个答案:

没有答案