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

后端 未结 1 1597
花落未央
花落未央 2020-12-10 00:42

I am getting the error \"Non-static method requires a target.\" when I run the following query:

var allPartners = DbContext.User
                           .         


        
相关标签:
1条回答
  • 2020-12-10 00:53

    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.

    0 讨论(0)
提交回复
热议问题