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