int sum=db.Where(x=>str.Contains(x)).Sum(x=>x.销量)//db是数据库实体 ------解决方案-------------------- 最好是x=>str.Split(',').Contains(x) ------解决方案-------------------- //偷懒做法:
int sum=db.Where(x=>","+str+",".Contains(","+x.年份+",")).Sum(x=>x.销量)//db是数据库实体 ------解决方案-------------------- 我现在用
return from p in db
where str.Contains(p.年份)
select p;
来获取数据集时出现如下错误:
对于方法 String.Contains,只支持可在客户端上求值的参数 ------解决方案-------------------- return from p in db.表名.ToList()
where str.Contains(p.年份)
select p; ------解决方案--------------------
设表名:TableA
年份字段:Year
销量字段:Sale
string[] str=new string[3]{"2012","2011","2009"};
var v=(from u in db.TableA
where str.Contains(u.Year.ToString())
select u.Sale).Sum(); ------解决方案-------------------- using System.Data.Linq.SqlClient;
然后参考一下代码即可
string[] listSearch = txtSearch.Value.Split(',');
List<string> list = listSearch.ToList();
List<A_WenDa> listWenDa = new List<A_WenDa>();
foreach (string search in listSearch)
{
var query = (from a in dc.A_WenDa
where SqlMethods.Like(a.GuanJianZi, string.Format("%{0}%", search))
&& a.City_Id == cityId && a.Available == true
select a).ToList<A_WenDa>();
listWenDa.AddRange(query.ToList<A_WenDa>());
}