2

Given I have the following entity with multiple collection properties...

public class Parent 
{
    public virtual int Id { get; set;}  
    public virtual ICollection<FirstChild> FirstChildren { get; set; }
    public virtual ICollection<SecondChild> SecondChildren { get; set; }
} 

Is there a way I can simultaneously eager load both of these properties using fluent NHibernate? Or simply eager load everything associated to the Parent.

If I have the following as my mapping...

public ParentMapping()
{
    Id(p => p.Id).GeneratedBy.Identity();

    HasMany(p => p.FirstChildren)
        .Table("FirstChildren")
        .KeyColumn("Id")
        .Inverse()
        .Cascade.AllDeleteOrphan()
        .Fetch.Join();

    HasMany(p => p.SecondChildren)
        .Table("SecondChildren")
        .KeyColumn("Id")
        .Inverse()
        .Cascade.AllDeleteOrphan()
        .Fetch.Join();
}

The mapping above results in the error:

'Cannot simultaneously fetch multiple bags'.

Using the Fetch.Join() in the mapping works if I use it on just one of the properties.

I am able to eager load everything by using ToFuture() queries, however, I would prefer to do this in the mapping.

TomJerrum
  • 584
  • 1
  • 5
  • 20

1 Answers1

0

You need to use ISet instead of ICollection to use that feature.

You can take a look here and here.

Najera
  • 2,869
  • 3
  • 28
  • 52
  • 1
    Is there a way of doing it without using ISet? As if I use Fetch.Join() on one of the collection properties it works fine. Its just when using it on multiple properties that the issue occurs. – TomJerrum Nov 02 '17 at 10:32