使用带有NHibernate的LInq时选择了多少列?

时间:2012-08-14 06:58:11

标签: linq nhibernate nhibernate-mapping nhibernate-3

我有两个班级

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....
      }
 }

我使用组件映射将Foo映射到电子邮件。每次只需要一封电子邮件。

当我选择

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

生成的SQL是

select emailType1, emailType2,.... From Foo

虽然我只期待

select emailType1 From Foo

1 个答案:

答案 0 :(得分:0)

GetEmail()在代码中实现,该代码位于Email类中。您如何看待nhibernate应该知道代码应该做什么?

它只获取整个电子邮件类(组件),然后让它决定返回什么。

相关问题