Non-static method requires a target. Entity Framework 5 Code First

若如初见. 提交于 2019-11-28 10:39:30

The problem boiled down to the query. My original question had this query:

var allPartners = DbContext.User
                       .Include(u => u.Businesses)
                       .Where(u => u.Businesses.Any(x => x.Id == currentBusinessId))
                       .ToList();

Which wasn't quite accurate, I had in fact removed the error in an attempt to ask my question succinctly. The query was actually:

var currentBusiness = GetBusiness();
var allPartners = DbContext.User
                       .Include(u => u.Businesses)
                       .Where(u => u.Businesses.Any(x => x.Id == currentBusiness.Id))
                       .ToList();

When the GetBusiness method returned null the error was thrown. Simply ensuring that I don't pass a null object into the expression made the error stop.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!