NHibernate using wrong table alias -


i trying filter collection based on foreign key. have 2 classes mapped with

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 query using

_session.linq<grouppriceoverride>.where(x => x.customerassetgroup.groupid == groupid) 

however generating

select this_.servicecode servicec1_9_0_, this_.groupid groupid9_0_, this_.price price9_0_ accgrouppriceoverride this_ customeras1_.groupid = @p0 

there clause referencing table alias doesn't exist(customeras1). alias crossing customerassetgroup there no need perform cross. i'm sure in mapping wrong can't find it. i've tried various column renaming in case presence of groupid in both tables causing problems didn't fix it. ideas?

edit found if queried doing

_session.linq<customerassetgroup>().where(x => x.groupid == groupid).firstordefault().priceoverrides; 

then got correct result. found if saved grouppriceoverride , queried using hql wouldn't found still find entity loading parent , looking @ collection of overrides.

_session.createquery("from grouppriceoverride i").list().count;//returns 0 _session.createquery("from customerassetgroupi").list().firstordefault().priceoverrides.count;//returns 1 

looks bug in old linq provider. file bug here:

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

you might able around via:

_session.linq<grouppriceoverride>.where(x => x.customerassetgroup == group) 

and let nhibernate figure out id. if don't have group already, this:

var group = _session.load<customerassetgroup>(groupid); _session.linq<grouppriceoverride>.where(x => x.customerassetgroup == group) 

the isession.load(id) generate proxy, won't hit database until access property (which wouldn't since you're using specify id).


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -