Entity Framework core .Include() issue

后端 未结 4 1264
长发绾君心
长发绾君心 2021-02-18 22:05

Been having a play about with ef core and been having an issue with the include statement. For this code I get 2 companies which is what i expected.



        
4条回答
  •  没有蜡笔的小新
    2021-02-18 22:59

    I test your code, this problem exist in my test. in this post LINK Proposed that use data projection. for your problem Something like the following, is work.

    [HttpGet]
    public dynamic Get()
    {
        var dbContext = new ApplicationContext();
    
        var result = dbContext.Companies
            .Select(e => new { e.CompanyName, e.Id, e.Employees, e.Admins })
            .ToList();
    
        return result;
    }
    

提交回复
热议问题