小编gvk*_*gvk的帖子

使用特定顺序在 mongoDB 中排序

Clients我目前正在寻找基于数组的特定顺序对子文档进行排序。

mongoDB的结构是

{
    "_id" : "1033",
    "Name" : "Test",
    "Clients" : [ 
        {
            "Id" : 1033,
            "Types" : [ 
                {
                    "Class" : "C",
                    "Service" : null
                },
                {
                    "Class" : "B",
                    "Service" : null
                }
            ]
        }, 
        {
            "Id" : 156136,
            "Types" : [ 
                {
                    "Class" : "A",
                    "Service" : null
                }, 
                {
                    "Class" : "B",
                    "Service" : null
                }, 
                {
                    "Class" : "C",
                    "Service" : null
                }, 
                {
                    "Class" : "D",
                    "Service" : null
                }
            ]
        }
    ] …
Run Code Online (Sandbox Code Playgroud)

c mongodb mongodb-.net-driver

8
推荐指数
2
解决办法
2388
查看次数

System.NotSupportedException - 无法比较'System.Linq.IQueryable类型的元素

我目前收到以下错误

> EntityFramework.SqlServer.dll中出现"System.NotSupportedException"类型的异常,但未在用户代码中处理

附加信息:无法比较'System.Linq.IQueryable`1 [[System.Int32,mscorlib,Version = 4.0.0.0,> Culture = neutral,PublicKeyToken = b77a5c561934e089]]'类型的元素.仅支持基本类型,>枚举类型和实体类型.

我的代码是

public List<User> GetActiveUsers(IEnumerable<int> officeIDs, string roleID, string query)
{
    return (from user in GetDBContext.User
            join userRole in GetDBContext.UserRole
                on user.UserID equals userRole.UserID
            join userOffice in GetDBContext.UserAuthorizedOffice
                on user.UserID equals userOffice.UserID
            where user.IsActive == true &&
                    user.UserTypeID == 1 &&
                    userOffice.IsAuthorized &&
                    userOffice.Office.IsActive &&
                    (officeIDs == null || officeIDs.Contains(userOffice.OfficeID)) &&
                    string.Equals(userRole.RoleID, roleID) &&
                    (user.FirstName + user.LastName).Contains(query)
            select user).ToList();
}
Run Code Online (Sandbox Code Playgroud)

这个问题似乎从这条线上抛出

(officeIDs == null || officeIDs.Contains(userOffice.OfficeID))

如果我删除第一个条件,officeIDs == …

.net c# linq entity-framework

7
推荐指数
2
解决办法
3047
查看次数

C#中列表的索引中的-1

我最近在我们的应用程序中遇到了下面的代码

var updateDefinition = new UpdateDefinitionBuilder<OverviewProfile>()
            .Set(a => a.Advisors[-1].IsCurrent, advisor.IsCurrent);
Run Code Online (Sandbox Code Playgroud)

在上面的代码,Advisors是一种ListUpdateDefinitionBuilder是从MongoDB的驱动程序.

能告诉我在列表索引中使用-1吗?

在以下评论/答案后编辑

OverviewProfile班是如下:

public class OverviewProfile: BaseInvestorProfile
{
    //Other properties

    public List<Advisor.View.Advisor> Advisors { get; set; }
    public OverviewProfile(int id): base(id)
    {
        Advisors = new List<Advisor.View.Advisor>();
    }
}
Run Code Online (Sandbox Code Playgroud)

这就是工作代码.此代码根据条件将数据更新到mongo db.此类中没有其他方法,只有其他属性.

这是一个类,但对于多个类的属性也有相同的用法,即使我们添加新List属性并检查,它也能正常工作.

c# mongodb-.net-driver

7
推荐指数
1
解决办法
666
查看次数

标签 统计

c# ×2

mongodb-.net-driver ×2

.net ×1

c ×1

entity-framework ×1

linq ×1

mongodb ×1