使用客户端 api 在 ravendb 中选择many的解决方法

发布于 2024-11-06 20:22:46 字数 882 浏览 0 评论 0原文

我有一个像这样的 ravendb 类:


        public class Student
        {
            public string Id { get; set; }
            public string TopLevelProperty { get; set; }
            public Dictionary<string, string> Attributes { get; set; }
            public Dictionary<string,List<Dictionary<string, string>>> CategoryAttributes { get; set; }
        }

和一个像这样的文档:
在此处输入图像描述

由于 selectmany,以下 linq 将无法工作:


                test = (from student in session.Query()
                        from eduhistory in student.CategoryAttributes["EducationHistory"]
                        where eduhistory["StartYear"] == "2009"
                              select student).ToList();

How can I get all Students where StartYear == 2009 年?

I have a ravendb class like such:


        public class Student
        {
            public string Id { get; set; }
            public string TopLevelProperty { get; set; }
            public Dictionary<string, string> Attributes { get; set; }
            public Dictionary<string,List<Dictionary<string, string>>> CategoryAttributes { get; set; }
        }

and a document like so:
enter image description here

The following linq will not work due to a selectmany:


                test = (from student in session.Query()
                        from eduhistory in student.CategoryAttributes["EducationHistory"]
                        where eduhistory["StartYear"] == "2009"
                              select student).ToList();

How can I get all students where StartYear == 2009?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

人│生佛魔见 2024-11-13 20:22:46

这样做是这样的:


test = session.Advanced.LuceneQuery()
            .Where("CategoryAttributes.EducationHistory,StartYear:2009")
            .ToList();

注意 EducationHistory 后面的逗号而不是点。这表明我们正在查看列表以查找名为 StartYear 的项目之一中的属性。
如果我想要大于:


test = session.Advanced.LuceneQuery()
            .Where("CategoryAttributes.EducationHistory,StartYear:[2009 TO null]")
            .ToList();

等等等等。

This does it :


test = session.Advanced.LuceneQuery()
            .Where("CategoryAttributes.EducationHistory,StartYear:2009")
            .ToList();

Notice the comma rather than a dot after EducationHistory. This indicates that we are looking at the list to find a property in one of the items named StartYear.
If I wanted greater than :


test = session.Advanced.LuceneQuery()
            .Where("CategoryAttributes.EducationHistory,StartYear:[2009 TO null]")
            .ToList();

etc etc.

喵星人汪星人 2024-11-13 20:22:46

这应该有效:

test = (from student in session.Query()
       where student.CategoryAttributes["EducationHistory"].Any(edu => edu["StartYear"]== "2009" )
       select student).ToList();

This should work:

test = (from student in session.Query()
       where student.CategoryAttributes["EducationHistory"].Any(edu => edu["StartYear"]== "2009" )
       select student).ToList();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文