fluent nhibernate - FluentNHibernate: Nested component mapping results in NHiberate QueryException -


hi have problem mapping in nhibernate. when run linq query referring 1 of component classes of entity, queryexception below:

could not resolve property: closedcases of: project.entities.headline

i have 1 table records want map multiple objects of headline entity.

question:

is there wrongly set in mapping?

my headline entity separated multiple logical classes can see below

  public class headline:entity   {     public virtual datetime date { get; set; }     public virtual teamtarget teamtarget { get; set; }   }    public class teamtarget : entity   {     public virtual datetime fromdate { get; set; }     public virtual datetime todate { get; set; }     public virtual targetitem achievedtarget { get; set; }     public virtual team team { get; set; }     }    public class targetitem : entity   {     public virtual decimal closedcases { get; set; }     public virtual decimal invoicing { get; set; }   } 

mapping file:

  public class headlinemap: classmap<headline>   {     public headlinemap()     {       table("headlines.headlines");       id(x => x.id).column("headlinesid");       map(x => x.date);       component(x => x.teamtarget, t =>       {         t.references(x => x.team).column("teamid").cascade.none();         t.component(x => x.achievedtarget, ti =>         {           ti.map(x => x.invoicing).column("teaminvoicing");           ti.map(x => x.closedcases).column("teamclosedcases");         });       }); 

the linq query running looks this:

decimal closedcases = _headlinerepository.all .where(x => x.date >= datetimeextensionmethods.firstdayofmonthfromdatetime(selectmonthfromdate) && x.date <= datetimeextensionmethods.lastdayofmonthfromdatetime(selectmonthfromdate) && x.teamtarget.team.id == teamid ).average(x => x.teamtarget.achievedtarget.closedcases); 

i know can access headline item using team entity team id , works, have problem mapping of achieved target. ideas?

i think mapping fine. far know, isn't possible query nested component linq nhibernate. can't understand joins do, becomes complex.

i think possible using nhibernate 3's queryover api using joinqueryover or joinalias. should read this: queryover in nh 3.0

maybe work:

headline headlinealias = null; teamtarget targetalias = null; team teamalias = null; targetitem targetitemalias = null;  var query = session.queryover<headline>(() => headlinealias)                    .joinalias(() => headlinealias.teamtarget, () => targetalias)                    .joinalias(() => targetalias.team, () => teamalias)                    .joinalias(() => targetalias.achievedtarget, () => targetitemalias)                    .where(x => x.date >= datetimeextensionmethods.firstdayofmonthfromdatetime(selectmonthfromdate) && x.date <= datetimeextensionmethods.lastdayofmonthfromdatetime(selectmonthfromdate))                    .and(() => teamalias.id == teamid)                    .select(projections.avg(() => targetitemalias.closedcases))                    .singleordefault<decimal>(); 

Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -