【发布时间】:2016-11-01 11:14:05
【问题描述】:
我有多个角色的用户
public class User
{
public int Id {get;set;}
public string Name {get;set;}
public List<Role> Roles {get;set;}
}
public class Roles
{
public int Id {get;set;}
public string Key{get;set;}
}
public class UserRoles
{
public int UserId {get;set;}
public int RoleId {get;set;}
}
我试图实现的是在一个查询中获得一个具有所有角色的用户,但到目前为止我失败了。 对于映射,我使用自定义的基于约定的映射器(我可以提供代码,但它相当大)
我尝试了 FetchOneToMany,并按照此处所述尝试了 Fetch
https://github.com/schotime/NPoco/wiki/One-to-Many-Query-Helpers https://github.com/schotime/NPoco/wiki/Version-3
但角色总是空的。 角色和用户本身已正确映射,我确实尝试指定关系,如
For<User>().Columns(x =>
{
x.Many(c => c.Roles);
x.Column(c => c.Roles).ComplexMapping();
}, true);
同样没有帮助,角色是空的。
我不知道我错过了什么。 有什么想法吗?
【问题讨论】:
标签: many-to-many mapping one-to-many npoco