我有以下三个实体类:
public class ApplicationUser : IdentityUser
{
public override string Id { get; set; }
[DefaultValue(false)]
[DisplayName("Is Active?")]
public bool IsActive { get; set; }
}
public class Reseller : Organisation
{
//public List<EmailAddress> EmailAdresses { get; set; }
[Required]
[DataType(DataType.EmailAddress)]
public override string EmailAddress { get; set; }
public List<Client> Clients { get; set; }
public List<ResellerUserConnector> Users { get; set; }
}
public class ResellerUserConnector
{
public ResellerUserConnector() { }
public ResellerUserConnector(string userId)
{
this.UserId = userId;
}
public Int64 Id { get; set; }
public string UserId { get; set; }
public Int64 ResellerId { get; set; }
public Reseller Reseller { get; set; }
}
逻辑上,Reseller
可以有零个或多个ApplicationUsers
。但是,由于某些限制,我们不允许将Reseller
作为ICollection<ApplicationUser>
属性。 EF也无法处理ICollection<string> property
的存储。因此,我创建了“关联”实体ResellerUserConnector
。
Reseller
的ApplicationUser实例列表时不成功(尽管直接浏览数据库会发现值和键正确存储在数据库中)。
这是LINQ to Entity代码,无法检索给定List<ApplicationUser>
的{{1}}实例。
Reseller
我是LINQ菜鸟所以请帮助一个家伙......
答案 0 :(得分:0)
var ids = r.Users.Select(c => c.UserId).ToList();
List<ApplicationUser> users =
(from u in identityDb.Users
where ids.Contains(u.Id)
select u).ToList<ApplicationUser>();