Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/321.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 无法将GetBytes方法转换为存储表达式_C#_Sql_Linq_Entity Framework - Fatal编程技术网

C# 无法将GetBytes方法转换为存储表达式

C# 无法将GetBytes方法转换为存储表达式,c#,sql,linq,entity-framework,C#,Sql,Linq,Entity Framework,我正在使用LINQ根据特定条件选择列表。属性值存储在字节数组中,稍后在存储在数据库表中时对其进行加密。我现在想在我的选择LINQ查询中使用此属性,但当我尝试时,它会引发以下异常: LINQ to Entities does not recognize the method 'Byte[] GetBytes(System.String)' method, and this method cannot be translated into a store expression. 这是我使用的代码:

我正在使用
LINQ
根据特定条件选择列表。属性值存储在
字节数组中
,稍后在存储在数据库表中时对其进行加密。我现在想在我的
选择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的日期。如何更改此设置?

只需先获取字节:

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;

只需先获取字节:

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;
将代码更改为:

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将代码更改为:

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的值

谢谢!工作得很有魅力!非常感谢。工作得很有魅力!