The parent class:
public class Group
{
public virtual int Id { get; set; }
public virtual string Name { get; set; }
public virtual byte[] Icon { get; set; }
public virtual IList<Category> Categories { get; set; }
}
The child class:
public class Category
{
public virtual int Id { get; set; }
public virtual string Description { get; set; }
public virtual Group Group { get; set; }
}
The mappings:
public CategoryMapping()
{
this.Table("[Category]");
this.Schema("[RSS]");
this.Id(x => x.Id, e => e.Generator(Generators.Identity));
this.Property(x => x.Description, e =>e.NotNullable(true));
this.ManyToOne(x => x.Group, e => e.Column("GroupId"));
}
public GroupMapping()
{
this.Table("[Group]");
this.Schema("[RSS]");
this.Id(x => x.Id, e => e.Generator(Generators.Identity));
this.Property(x => x.Name, e => e.NotNullable(true));
this.Property(x => x.Icon, e => e.NotNullable(false));
this.Bag(x => x.Categories, mapper => mapper.Key(e => e.Column("GroupId")), relation => relation.OneToMany());
}
The problem is when a try to get the group list
var groupList = session.Query<Group>()
.Fetch(x => x.Categories)
.Take(10)
.ToList();
the groupList above end up with duplicated items, like
- Group 1
- Category A
- Category B
- Category C
- Group 1
- Category A
- Category B
- Category C
- Group 1
- Category A
- Category B
- Category C
And the list should be
- Group 1
- Category A
- Category B
- Category C
- Group 2
- Category D
- Category E
- Category F
something missing in code ?
Thanks in advance.