我有一个简单的问题,但似乎找不到解决方法.我正在使用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) 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”,但我想实现对象。也许那里不可能?