Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/entity-framework/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 实体框架核心-can';我似乎没有使用Include_Asp.net_Entity Framework_Asp.net Core - Fatal编程技术网

Asp.net 实体框架核心-can';我似乎没有使用Include

Asp.net 实体框架核心-can';我似乎没有使用Include,asp.net,entity-framework,asp.net-core,Asp.net,Entity Framework,Asp.net Core,我已经从事BI项目管理工作好几年了,现在又回到了一些web应用开发工作中。我正在构建一个asp.net核心应用程序并使用EF核心。EF Core上没有启用延迟加载,这很好。我想我想使用.Include加载相关对象 所以如果你有 public class Customer { public int CustomerId { get; set; } public Address { get; set; } } public ViewResult List()

我已经从事BI项目管理工作好几年了,现在又回到了一些web应用开发工作中。我正在构建一个asp.net核心应用程序并使用EF核心。EF Core上没有启用延迟加载,这很好。我想我想使用.Include加载相关对象

所以如果你有

 public class Customer {
       public int CustomerId { get; set; }
       public Address { get; set; }
 } 

 public ViewResult List()
 {
       CustomerListViewModel customersListViewModel = new CustomerListViewModel();
       customersListViewModel.Customers = _customerRepository.Customers.??? // Include does not resolve...

        return View(customersListViewModel);
    }

我试图返回一个iEnumble的客户,他们也热切地加载地址。其他答案建议我应该能够使用.Include(),但这似乎不是一个适合我的方法

.Include()在EF Core中可用。您所说的对我来说似乎不可用的方法是什么意思?您需要使用Microsoft.EntityFrameworkCore引用
Microsoft.EntityFrameworkCore.dll
程序集和
在源代码文件中。请不要将EF与未知存储库模式实现混合使用。
Include
IQueryable
的扩展方法。好的,我在CustomRepository中添加了“使用Microsoft.EntityFrameworkCore;”,然后添加了appDbContext.Customers.Include(“地址”);这似乎有效。您可能还希望使用Include的lambda重载。包括(a=>a.Address)。如果您引用的表的访问有任何问题,那么编译时错误比运行时错误更有好处。Include()在EF Core中可用。您所说的什么方法对我来说似乎不可用?您需要使用Microsoft.EntityFrameworkCore引用
Microsoft.EntityFrameworkCore.dll
程序集和
在源代码文件中。请不要将EF与未知存储库模式实现混合使用。
Include
IQueryable
的扩展方法。好的,我在CustomRepository中添加了“使用Microsoft.EntityFrameworkCore;”,然后添加了appDbContext.Customers.Include(“地址”);这似乎有效。您可能还希望使用Include的lambda重载。包括(a=>a.Address)。如果访问您引用的表时出现任何问题,那么编译时错误比运行时错误更有好处