我正在使用此代碼作爲一個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