NHibernate using an invalid table alias

I am trying to filter a collection based on a foreign key. I have two classes that are displayed using

public class GroupPriceOverrideMap:ClassMap<GroupPriceOverride>
    {
        public GroupPriceOverrideMap()
        {
            CompositeId()
                .KeyReference(x => x.Service,"ServiceCode")
                .KeyReference(x => x.CustomerAssetGroup, "GroupID");

            Map(x => x.Price);

            Table("accGroupPriceOverride");
        }
    }

public class CustomerAssetGroupMap:ClassMap<CustomerAssetGroup>
    {
        public CustomerAssetGroupMap()
        {
            Id(x => x.GroupID).Unique();

            Map(x => x.Description);

            References(x => x.Customer).Column("CustomerID");

            HasMany<GroupPriceOverride>(x => x.PriceOverrides).KeyColumn("GroupID");

            Table("accCustAssetGroup");
        }
    }

I request it with

_session.Linq<GroupPriceOverride>.Where(x => x.CustomerAssetGroup.GroupID == groupID)

However, this generates

SELECT this_.ServiceCode as ServiceC1_9_0_, this_.GroupID as GroupID9_0_, this_.Price as Price9_0_ FROM accGroupPriceOverride this_ WHERE customeras1_.GroupID = @p0

where the sentence refers to a table alias that does not exist (customeras1). This is probably an alias for crossbreeding with the customerassetgroup team, but there is no need to complete this cross. I am sure that this is just something in my comparison with the wrong one, but I cannot find it. I tried renaming the columns in case the presence of the groupID in both tables caused problems, but this did not fix. Any ideas?

Edit I found that if I ask to do

_session.Linq<CustomerAssetGroup>().Where(x => x.GroupID == groupID).FirstOrDefault().PriceOverrides;

. , GroupPriceOverride, HQL, , , .

_session.CreateQuery("FROM GroupPriceOverride i").List().Count;//returns 0
_session.CreateQuery("FROM CustomerAssetGroupi").List().FirstOrDefault().PriceOverrides.Count;//returns 1
+5
1

LINQ. :

https://nhibernate.jira.com/secure/Dashboard.jspa

, :

_session.Linq<GroupPriceOverride>.Where(x => x.CustomerAssetGroup == group)

NHibernate . , :

var group = _session.Load<CustomerAssetGroup>(groupID);
_session.Linq<GroupPriceOverride>.Where(x => x.CustomerAssetGroup == group)

ISession.Load(id) -, , ( , ).

+1

All Articles