2013-10-08 26 views
0

我正在使用LINQ來根據特定條件選擇列表。該屬性值存儲在byte array中,後者在存儲到數據庫表中時被加密。我想現在我SELECT LINQ查詢中使用此屬性,但它拋出以下異常,當我嘗試:GetBytes方法無法轉換爲商店表達式

LINQ to Entities does not recognize the method 'Byte[] GetBytes(System.String)' method, and this method cannot be translated into a store expression. 

這是我使用的代碼:我想選擇

var result = (from history in context.Histories 
           where history.ID == Id & 
           (history.Salary != null || history.Salary != Encoding.ASCII.GetBytes("0")) 
           select (DateTime?)history.Date).Max(); 
       return result; 

歷史記錄表中的日期,這些ID的工資不等於null或0.我該如何更改?

回答

4

首先就得到字節:

var bytes = Encoding.ASCII.GetBytes("0"); 

var result = (from history in context.Histories 
           where history.ID == Id & 
          (history.Salary != null || history.Salary != bytes) 
          select (DateTime?)history.Date).Max(); 
      return result; 
+0

謝謝

var bytes = Encoding.ASCII.GetBytes("0"); var result = (from history in context.Histories where history.ID == Id & (history.Salary != null || history.Salary != bytes) select (DateTime?)history.Date).Max(); return result; 

LINQ無法判斷您的GetBytes會!像魅力一樣工作! – faizanjehangir

2

你的代碼更改爲:當它會將您的查詢SQL

相關問題