Cannot convert lambda expression to type 'string' because it is not a delegate type

前端 未结 5 1641
生来不讨喜
生来不讨喜 2021-02-19 05:32

In my controller i am trying to use include with EF4 to select related entities, but the lambda expression is throwing the following error,

i have the related entity de

5条回答
  •  不知归路
    2021-02-19 06:05

    The Include method expects a string, not a lambda:

    public ViewResult List()
    {
        var sites = context.CustomerSites.Include("Customer");
        return View(sites.ToList());
    }
    

    Of course you could write a custom extension method which would work with lambda expressions and make your code independant of some magic strings and refactor friendlier.

    But whatever you do PLEASE OH PLEASE don't pass EF autogenerated objects to your views. USE VIEW MODELS.

提交回复
热议问题