public EmployeeDTO AuthenticateEmployee(string username, string password)
{
try
{
var userLogin = UnitOfWork.UserLoginRepository.Get(x => x.UserName == username).FirstOrDefault();
if (userLogin == null)
return null;
else
{
var userStore = new UserStore<IdentityUser>();
var userManager = new UserManager<IdentityUser>(userStore);
// this throws an error.
var user = userManager.Find("username", "password");
}
}
}
导致错误:
无法加载类型"System.ComponentModel.DataAnnotations.Schema"。IndexAttribute' from assembly 'EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
我使用的是EF 6.0, Microsoft.AspNet.Identity.EntityFramework
版本2.0。
我无法使用身份执行基于EF的任何操作,我必须做任何事情,我的EDMX在另一个类库中。我想是DLL的问题。
请帮我与EF使用identity。
我已经浏览了Msdn
IndexAttribute
是EF 6.1中包含的新内容之一。所以问题是你引用了错误的EF版本(6.0)。请在您的项目中参考6.1。
查看EF版本历史记录
我也有这个错误,但在包中的所有EntityFramework引用。配置指向最新的EF版本(在我的例子中是6.1.3)。我卸载了出现错误的项目,并注意到EF的提示路径是旧的。更新后,它们可以正常工作。
老引用:
<Reference Include="EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
<HintPath>..packagesEntityFramework.6.0.0libnet45EntityFramework.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="EntityFramework.SqlServer, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
<HintPath>..packagesEntityFramework.6.0.0libnet45EntityFramework.SqlServer.dll</HintPath>
<Private>True</Private>
</Reference>
更新工作参考:
<Reference Include="EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
<HintPath>..packagesEntityFramework.6.1.3libnet45EntityFramework.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="EntityFramework.SqlServer, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
<HintPath>..packagesEntityFramework.6.1.3libnet45EntityFramework.SqlServer.dll</HintPath>
<Private>True</Private>
</Reference>