小编hdo*_*itc的帖子

如何将 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
查看次数

如何在.Net Core模型上自定义MongoDb集合名称?

我找不到 MongoDb 的注释,.Net Core 模型中可以修改集合名称。在 SQL 数据库中,它将是 [Table("all_sessions")]。

我的型号名称和系列名称不同。我没有更改型号或系列名称。

public class Session
    {
        [BsonId]
        [BsonRepresentation(BsonType.ObjectId)]
        [BsonElement("_id")]
        public string Id { get; set; }

        [BsonElement("expires")]
        public string Expires { get; set; }

        [BsonElement("session")]
        public string Session { get; set; }
    }
Run Code Online (Sandbox Code Playgroud)

我的集合名称是 all_sessions。我希望使用 all_sessions 集合获得工作会话模型。

mongodb .net-core asp.net-core

2
推荐指数
1
解决办法
4015
查看次数