我正在使用此代码作为一个DataGridView过滤器:System.NotSupportedException而试图通过ID C#过滤
private void consultarPorCriterio()
{
var inspec = from ins in entities.Inspeccions
where (ins.Ralladuras.StartsWith(txtTextoABuscar.Text) ||
ins.Repuesta.StartsWith(txtTextoABuscar.Text)||
ins.ID.ToString().StartsWith(txtTextoABuscar.Text)
)
select ins;
dgvInspeccion.DataSource = inspec.ToList();
}
它过滤如果我删除:
ins.ID.ToString().StartsWith(txtTextoABuscar.Text).
如果我不” t删除那部分代码我得到这个错误:
Exception not handled... 'System.NotSupportedException' in mscorlib.dll
Aditional Info: LINQ to Entities does not recognize the method 'System.String ToString()' method, and this method cannot be translated into a store expression.
有人知道我在做什么错吗?
,因为它不能被转换为T-SQL,LINQ到实体无法识别它,看看这个答案:http://stackoverflow.com/a/34061692/2946329 –
我从我的老师程序采取此代码,在他的程序中,他做的和我试图做的一样,我的意思是按ID过滤。为什么它适合他而不适合我? –
ins.ID的底层数据类型是什么? – tolanj