Extra columns selected when using LInq with NHibernate?

149 views Asked by At

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
1

There are 1 answers

2
Firo On BEST ANSWER

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.