var data = from px in db.vw_ygpx
// orderby px.ygid descending
select px;
if (!string.IsNullOrEmpty(key))
{
key = key.Trim();
// data = data.Where(d => d.ygmc.Contains(key) || d.gh.Contains(key));
data = from d in data
where d.ygmc.Contains(key) || d.gh.Contains(key)
//where SqlMethods.Like(d.ygmc , "%肖%")
select d ;
}
var res=(from d in data
select d).AsEnumerable().OrderByDescending(d => d.ygid).Skip((pageIndex - 1) * pageSize).Take(pageSize);
return JsonHelper.ToJson(res);//这是一个未解之迷,当不加AsEnumerable()时就会报丢失字段,当where d.ygmc.Contains(key) 直接写成where d.ygmc.Contains("肖")时又不会报错