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的值谢谢!工作得很有魅力!非常感谢。工作得很有魅力!