gpt4 book ai didi

ef-core-2.0 - Entity Framework 核心重用一组包含语句

转载 作者:行者123 更新时间:2023-12-04 02:59:07 25 4
gpt4 key购买 nike

如何清理我的实体“包含”以重用同一组语句?我试图在保持 DRY 的同时重用一组 Includes。


_context.Accounts
.Include(x=> x.Status)
.Include(x=> x.Type)
.Include(x=> x.Phones)
.Include(x=> x.Users)
.Include(x=> x.Admins)

后:
_context.Accounts.CustomIncludes()

最佳答案

尝试这个:

public static class DataExtensions
{
public static Microsoft.EntityFrameworkCore.Query.IIncludableQueryable<Account, List<Admin>> CustomIncludes(this DbSet<Account> accounts)
{
return accounts
.Include(p => p.Status)
.Include(p => p.Type)
.Include(p => p.Phones)
.Include(p => p.Users)
.Include(p => p.Admins);
}
}

那你可以说

context.Accounts.CustomIncludes();

关于ef-core-2.0 - Entity Framework 核心重用一组包含语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50935667/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com