开发者

NHibertnate mapping HasManyToMany results in CROSS JOIN

开发者 https://www.devze.com 2023-01-11 11:26 出处:网络
I\'m trying to add a mapping to the table IdentityGroup which has ManyToMany IdentityUsers thought the table IdentityGroupIdentitiy. However when I add the mapping. The result seems to be a something

I'm trying to add a mapping to the table IdentityGroup which has ManyToMany IdentityUsers thought the table IdentityGroupIdentitiy. However when I add the mapping. The result seems to be a something like a cross join.

Expected result for a group with two users:

Group 1:
    User 1
    User 2

Current result for a group with two users:

Group 1:
    User 1
    User 2
Group 1:
    User 1
    User 2

My mapping looks like this:

mapping.HasManyToMany<IdentityUser>(x => x.Users)
       .Table("IdentityGroupIdentity")
       .ParentKeyColumn("identityGroup_cid")
       .ChildKeyColumn("identity_cid");
开发者_运维知识库

Code to fetch the data:

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" }); }
}

Ant ideas?


Resolved by not "Expanding" the Users-property when fetching...

0

精彩评论

暂无评论...
验证码 换一张
取 消