这是我的linq查询,在下面的代码中有一些具有空值的变量,因此当所有6个变量都出现时,此linq查询器不起作用,那么它如何正常工作,如何解决它,请有人帮我朋友。。。
public JsonResult ItemMaster(string ItemName, string Brand, string Color, string Dimen, string Size, string Char)
{
var item = entity.TblItemMasters.FirstorDefault(x => x.ItemName == ItemName && x.BrandName == Brand && x.Color == Color && x.Dimensions == Dimen && x.Size == Size && x.Charecterstitics == Char);
if (item == null)
{
//do something
}
else{
item.ItemCode
}
}
这可能是你想要的
public JsonResult ItemMaster(string ItemName, string Brand, string Color, string Dimen, string Size, string Char)
{
var data = from x in entity.TblItemMasters
where (ItemName == null || x.ItemName == ItemName)
&& (Brand == null || x.BrandName == Brand )
&& (Dimen == null || x.Dimensions == Dimen)
&& (Size == null || x.Size == Size )
&& (Char== null || x.Charecterstitics == Char)
select x;
if(data.Count() == 0)
var Item=data.FirstOrDefault();
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句