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怎么转。谢谢
------解决方案--------------------
------解决方案--------------------
------解决方案--------------------
------解决方案--------------------1. 我贴的代码,最后一句有写错的地方:Url_IMDB 应该为 Name_EN
|| q.Url_IMDB.Contains(
string.IsNullOrEmpty(bean.Name_EN) ? "$$$" : bean.Name_EN);
2. 更好的做法是#2楼的做法。
and 的时候直接 where
or 的时候用 union