0
我想添加一個映射到表IdentityGroup,它有ManyToMany IdentityUsers認爲表IdentityGroupIdentitiy表。但是,當我添加映射。結果似乎是一個像交叉連接的東西。NHibertnate映射HasManyToMany結果CROSS JOIN
爲一組與兩個用戶預期的結果:
Group 1:
User 1
User 2
目前的結果爲一組有兩個用戶:
Group 1:
User 1
User 2
Group 1:
User 1
User 2
我的映射是這樣的:
mapping.HasManyToMany<IdentityUser>(x => x.Users)
.Table("IdentityGroupIdentity")
.ParentKeyColumn("identityGroup_cid")
.ChildKeyColumn("identity_cid");
代碼取數據:
public IQueryable<T> Find<T>(params string[] propertiesToLoad)
{
var query = session.Linq<T>();
foreach (var propName in propertiesToLoad)
query.Expand(propName);
if (typeof(T) is ISoftDeletable)
query.Where(x => !(x as ISoftDeletable).IsDeleted);
return query;
}
[...]
public IQueryable<IdentityGroup> Groups
{
get { return Find<IdentityGroup>(new string[] { "DefaultOrganization", "DefaultLocation", "Users" }); }
}
螞蟻的想法?
您可以發佈您使用獲取組的代碼嗎?我懷疑你可能需要使用DistinctRootEntityTransformer來扁平化對象圖表,如果你急切地加載用戶和組。 – DanP 2010-08-12 10:57:40
編輯該帖子 – dale 2010-08-12 11:17:10