0

LINQ特定の条件に基づいてリストを選択するために使用しています。属性値は に保存されbyte array、後でデータベース テーブルに保存するときに暗号化されます。今すぐクエリでこの属性を使用したいのですSELECT LINQが、しようとすると次の例外がスローされます。

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;

給与が null または 0 でない ID の履歴テーブルから日付を選択したいのですが、これを変更するにはどうすればよいですか?

4

2 に答える 2

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;
于 2013-10-08T11:33:19.920 に答える
2

コードを次のように変更します。

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 はクエリを SQL に変換するときに GetBytes を評価できません

于 2013-10-08T11:34:24.300 に答える