Question

I have two classes

Public class Foo 
{ 
   int Id {get;set;}
   Email DefaultEmail {get;set;} 
}

Public class Email 
{ 
   string main {get;set;} 
   string backup {get;set;}
   string recover {get;set;}
}

 Public string GetEmail(EnType)
 {
      switch(EnType)
      {
            Case EnType.Type1:
                return this.main;

            // others condition....
      }
 }

I map Foo to Email using component map. Each time only one email is required.

when I select

Session.Query.select(x => x.email.getEmail(EnType.Type1))

SQL generated is

select emailType1, emailType2,.... From Foo

while I expect only

select emailType1 From Foo
Was it helpful?

Solution

GetEmail() is implemented in code which is located in the Email class. How do you think nhibernate should know what the code is supposed to be doing?

It just fetches the whole email class (component) and then let it decide what to return.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top