我创建了一个继承自ApplicationUser
的类,如:
public class Company : ApplicationUser
{
public string CompanyName { get; set; }
public String Boss { get; set; }
public string Slogan{ get; set; }
}
EF会将一个Discriminator列添加到dbo.AspNetUsers
我从Company
类获得了这样的属性:
Company cm = (Company)db.Users.Find(id);
工作正常,但如何获得Company
个用户列表(即Discriminator == "Company"
)?
答案 0 :(得分:2)
您需要使用OfType<...>()
扩展程序:
var companyUsers = db.Users.OfType<Company>();
这样做会运行这样的SQL:
SELECT
[Extent1].Id,
[Extent1].Column2.
--etc
FROM [dbo].[AspNetUsers] AS [Extent1]
WHERE [Extent1].[Discriminator] = Company'