我正在创建asp.net身份验证。我正在关注这篇文章http://www.jamessturtevant.com/posts/ASPNET-Identity2.0-Custom-Database/
我有一个从IUser扩展的User类 和以下课程
CustomSignInManager:SignInManager<User,string>
CustomUserManager : UserManager<User>
CustomUserStore : IUserStore<CustomUser>
我有LINQ to SQL类
以下是我的CustomUserStore类
public class CustomUserStore:IUserStore<User>
{
private UserDataDataContext database;
public CustomUserStore()
{
this.database = new UserDataDataContext();
}
public Task CreateAsync(User user)
{
// TODO
throw new NotImplementedException();
}
public void Dispose()
{
this.database.Dispose();
}
public Task UpdateAsync(User user)
{
// TODO
throw new NotImplementedException();
}
public Task DeleteAsync(User user)
{
// TODO
throw new NotImplementedException();
}
public async Task<User> FindByIdAsync(string userId)
{
User user = await this.database.Users.Where(c => c.UserName == userId).FirstOrDefaultAsync();
return user;
}
public async Task<User> FindByNameAsync(string userName)
{
User user = await this.database.Users.Where(c => c.UserName == userName).FirstOrDefaultAsync();
return user;
}
}
我遇到的问题是以下行
User user = await this.database.Users.Where(c => c.UserName == userId).FirstOrDefaultAsync();
在
public async Task<User> FindByIdAsync(string userId)
方法
我得到的错误是
无法将类型'testSys.User'隐式转换为'testSys.Models.User'testSys testSys \ testSys \ Models \ CustomUserStore.cs 49 Active
如何解决此错误?