日期:2014-05-20  浏览次数:20690 次

LINQ语句的问题(急!)
tring sql = @"select * from dbo.tb_Movie where 1=1";
  if (bean != null)
  {
  sql += string.IsNullOrEmpty(bean.Name_CN.ToString()) ? "" : " and Name_CN like '%" + bean.Name_CN + "%'";
  sql += string.IsNullOrEmpty(bean.Year_Movie.ToString()) ? "" : " and Year_Movie like '%" + bean.Year_Movie + "%'";
  sql += string.IsNullOrEmpty(bean.Type_Movie.ToString()) ? "" : " and Type_Movie like '%" + bean.Type_Movie + "%'";
  sql += string.IsNullOrEmpty(bean.Url_IMDB.ToString()) ? "" : " or Url_IMDB like '%" + bean.Url_IMDB + "%'";
  sql += string.IsNullOrEmpty(bean.Name_EN.ToString()) ? "" : " or Name_EN like '%" + bean.Name_EN + "%'";
  sql += string.IsNullOrEmpty(bean.Path_Save.ToString()) ? "" : " and Path_Save like '%" + bean.Path_Save + "%'";
  }
  sql += "order by ID_Movie desc";

这个逻辑的语句,转正LINQ怎么转。谢谢

------解决方案--------------------
探讨
引用:
这最好直接用Dynamic Linq来处理。

http://weblogs.asp.net/scottgu/archive/2008/01/07/dynamic-linq-part-1-using-the-linq-dynamic-query-library.aspx

嗯,ScottGu 很给力。

动态LINQ的缺点是没有办法进……

------解决方案--------------------
探讨

引用:
引用:
这最好直接用Dynamic Linq来处理。

http://weblogs.asp.net/scottgu/archive/2008/01/07/dynamic-linq-part-1-using-the-linq-dynamic-query-library.aspx

嗯,ScottGu 很给……

------解决方案--------------------
探讨

引用:
这最好直接用Dynamic Linq来处理。

http://weblogs.asp.net/scottgu/archive/2008/01/07/dynamic-linq-part-1-using-the-linq-dynamic-query-library.aspx

嗯,ScottGu 很给力。

动态LINQ的缺点是没有办法……

------解决方案--------------------
1. 我贴的代码,最后一句有写错的地方:Url_IMDB 应该为 Name_EN
|| q.Url_IMDB.Contains(
string.IsNullOrEmpty(bean.Name_EN) ? "$$$" : bean.Name_EN);

2. 更好的做法是#2楼的做法。
and 的时候直接 where
or 的时候用 union