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...
精彩评论