2010-05-23 58 views
3

我收到以下錯誤:成員[類]有沒有支持轉換爲SQL

Error Message:The member 'Company.ProductCore.Core.Domain.Account.Email' has no supported translation to SQL.

我的方法是這樣的:

public Account GetAccountByEmail(string email) 
     { 
      Account account; 

      using (WorkbookDataContext dc = _conn.GetContext()) 
      { 
       account = (from a in dc.Accounts 
          join em in dc.Emails on a.AccountId equals em.AccountId 
          where a.Email.EmailAddress == email 
          select a).FirstOrDefault(); 
      } 

      return account; 

     } 

我的賬戶類具有一個getter/setter方法是揭露電子郵件:

public Email Email 
     { 
      get { return _email; } 
      set { _email = value; } 
     } 

而我的電子郵件是一個LINQ對象。

我有一種感覺,問題是我爲我使用LINQ對象電子郵件 屬性?我是LINQ的新手,我不確定爲什麼會發生這種情況。

幫助表示讚賞,感謝...

+0

什麼是LINQ對象?請向我們展示您的「電子郵件」類。 – SLaks 2010-05-23 22:02:34

回答

2

認爲這是你追求的(你需要直接引用的電子郵件地址,通過已知的映射),但我不能100%當然不知道你的結構:

  account = (from a in dc.Accounts 
         join em in dc.Emails on a.AccountId equals em.AccountId 
         where em.EmailAddress == email 
         select a).FirstOrDefault(); 

爲什麼?部分:
簡而言之,LINQ沒有關於該屬性是什麼的映射知識......並且不能創建SQL查詢,因爲它不知道,所以當它試圖生成一個運行時錯誤時來自表達式樹的查詢。

您不能在查詢中使用屬性,除非LINQ知道它映射到的是什麼表/列/函數,沒有這個...它根本無法將其轉換爲SQL或從SQL轉換。

+0

謝謝尼克 - 就是這樣。 – 2010-05-23 23:45:00

相關問題