使用. contains的Linq To SQL方法失败
本文关键字:SQL 方法 失败 To Linq contains 使用 | 更新日期: 2023-09-27 18:05:32
我有下面的Linq To SQL方法。当我逐步遍历代码时,spcCodeIDs
包含我期望的七个条目。但是我得到了
Method 'Boolean Contains(System.String)' has no supported translation to SQL.
我错过了什么?
public static DataTable GetSPCCodeList()
{
using (var context = ProviderDataContext.Create())
{
IQueryable<tblProviderAdminSPCCode> tSPCCode = context.GetTable<tblProviderAdminSPCCode>();
IList<string> spcCodeIDs = BLLCmo.FCApprovedSPCsForGreenSheet();
return (tSPCCode
.Where(spcCode => spcCode.Inactive == null && spcCodeIDs.Contains(spcCode.SPCCodeID))
.OrderBy(spcCode => spcCode.SPCCodeID)
.Select(spcCode => new { spcCode.SPCCodeID, spcCode.SPCDescription, spcCode.SPCCategoryID }))
.CopyLinqToDataTable();
}
}
LINQ to SQL只能支持具体列表的Contains转换,而不支持IList接口。尝试从
更改行IList<string> spcCodeIDs = BLLCmo.FCApprovedSPCsForGreenSheet();
List<string> spcCodeIDs = BLLCmo.FCApprovedSPCsForGreenSheet().ToList();
您需要将字符串作为参数传递给Contains。所以尝试传递spccode。spccodeid。tostring ()