我正在开发MVC应用程序。
我正在尝试在控制器中编写LINQ语句,但它给出了错误...
ViewBag.CompanyIdList = new SelectList(db.Companies.OrderBy(t => t.Name).Where(t=>t.IsDeleted!=true || t=>t.IsTransfer !=true) , "Id", "Name");
这是什么问题?
问题已解决,感谢 Mystere Man
ViewBag.CompanyIdList = new SelectList(db.Companies.OrderBy(t => t.Name).Where(t => (t.IsDeleted == false || t.IsDeleted == null) && (t.IsTransfered == false || t.IsTransfered == null)), "Id", "Name");
答案 0 :(得分:1)
它所说的t不存在的问题是由此引起的:
.Where(t=>t.IsDeleted!=true || t=>t.IsTransfer !=true)
这应该是:
.Where(t=>t.IsDeleted!=true || t.IsTransfer !=true)
您只在表达式中使用lambda一次。事实上,你可以缩短它:
.Where(t => !t.IsDeleted || !t.IsTransfer)