相关疑难解决方法(0)

实体框架核心2.0.1渴望加载所有嵌套的相关实体

我有一个简单的问题,但似乎找不到解决方法.我正在使用Entity Framework Core版本2.0.1,并且希望默认情况下急切加载我的所有实体.

例:

public class Order
{
    public int Id { get; set; }
    public string Name { get; set; }
    public int CustomerId { get; set; }
    public Customer Customer { get; set; }
}

public class Customer
{
    public int Id { get; set; } 
    public string Name { get; set; }
    public int AddressId { get; set; }
    public Address Address { get; set; }
}

public class Address
{
    public int Id { get; set; …
Run Code Online (Sandbox Code Playgroud)

c# eager-loading entity-framework-core

12
推荐指数
2
解决办法
8332
查看次数

如何将 ThenInclude 实现到 EF Core 自定义规范中?

EF Core 3.1 我看过规范示例,并且想要实现 ThenInclude 模式。

public static class QuerySpecificationExtensions
{
    public static IQueryable<T> Specify<T>(this IQueryable<T> query, ISpecification<T> spec) where T : class
    {
        // fetch a Queryable that includes all expression-based includes
        var queryableResultWithIncludes = spec.Includes
            .Aggregate(query,
                (current, include) => current.Include(include));

        // modify the IQueryable to include any string-based include statements
        var secondaryResult = spec.IncludeStrings
            .Aggregate(queryableResultWithIncludes,
                (current, include) => current.Include(include));

        // return the result of the query using the specification's criteria expression
        return secondaryResult.Where(spec.Criteria);
    }
}
Run Code Online (Sandbox Code Playgroud)

我可以将其添加到字符串中,例如“User.UserRole.Role”,但我想实现对象。也许那里不可能?

c# entity-framework-core

3
推荐指数
1
解决办法
968
查看次数

标签 统计

c# ×2

entity-framework-core ×2

eager-loading ×1