我在我的应用程序中实现了.Net Identity,并且我有一个名为Person的类,它继承了IdentityUser。这是我的Person类:
public class Person : IdentityUser
{
[Required]
[StringLength(50, ErrorMessage = "First name cannot be longer than 50 characters.")]
public string FirstName { get; set; }
[Required]
[StringLength(150, ErrorMessage = "Last name cannot be longer than 150 characters.")]
public string LastName { get; set; }
}
以下是我尝试绑定现有用户的代码(继承IdentityUser的人员)
protected void Page_Load(object sender, EventArgs e)
{
var userStore = new UserStore<IdentityUser>(new gEchoLuDBContext());
var userManager = new UserManager<IdentityUser>(userStore);
List<Person> users = new List<Person>();
users = (List<Person>)(from u in userManager.Users
select u);
fw_CreateUser.DataSource = users;
fw_CreateUser.DataBind();
}
但是我得到了LinQ语句行的错误,它不允许从IdentityUser转换为Person:
无法转换类型为'System.Data.Entity.Infrastructure.DbQuery
1[Microsoft.AspNet.Identity.EntityFramework.IdentityUser]' to type 'System.Collections.Generic.List
1 [gEchoLu.Model.Person]'的对象。
这不奇怪吗?