C# 如何在where和select语句中的ef查询中使用子字符串
您好,如何在C# 如何在where和select语句中的ef查询中使用子字符串,c#,linq,c#-4.0,C#,Linq,C# 4.0,您好,如何在EF查询where和select语句中使用substring 我的查询不计算要执行的数据库中的任何记录 但在数据库中有13359条记录 我的问题如下 string subautoassettype, subautocat, subautocat1 ; string autoidstring; autocat = cmbcategory.Text; autocat1 = cmbcategory1.Text; autocat2 = cmbcategory2.Text;
EF
查询where
和select
语句中使用substring
我的查询不计算要执行的数据库中的任何记录
但在数据库中有13359条记录
我的问题如下
string subautoassettype, subautocat, subautocat1 ;
string autoidstring;
autocat = cmbcategory.Text;
autocat1 = cmbcategory1.Text;
autocat2 = cmbcategory2.Text;
subautoassettype = autocat.Substring(0, 3);
subautocat = autocat1.Substring(0, 3);
subautocat1 = autocat2.Substring(0, 3);
autoidstring = subautoassettype + subautocat + subautocat1 + "-";
var varmaxidcheck = cnx.item_master.Where(c => c.Item_ID.Substring(0, 9) == autoidstring)
.Select(gd => new { gd.Item_ID }).ToList();
if (varmaxidcheck.Count > 0)
{
foreach (var it11 in varmaxidcheck)
{
string kij = it11.Item_ID;
}
}
示例输出预期值:
cnx.item_master(where c=> c.FixBooChe-0013346 == FixBooChe-).Select(fg=>fg.Item_ID);
请帮我解决这个问题
此外,我还包括SQL查询
select max(substring(Item_ID,11,6)) from item_master where substring(Item_ID,1,9) = 'FixEleCre';
使用而不是==
:
var varmaxidcheck = cnx.item_master.Where(c => c.Item_ID.Substring(0, 9)
.Contains(autoidstring))
.Select(gd => new { gd.Item_ID })
.ToList();
因为在Where
子句中可能没有精确的匹配字符串。可以使用skip()和take()。