1

Trying to figure out how to access nested array properties when using the strongly typed query builders for mongodb in c#. Lets say I have the following classes:

public class V {
    public Guid _id { get; set; }
    public List<S> S { get; set; }
}

public class S {
    public Guid I { get; set;}
    /* other fields */
}

V is the document type. I want to build a query like this:

var id = Guid.NewGuid();
var query = Query<V>.EQ(v => v.S.I, id);

However that doesn't compile because the S property on V is a List. The resulting mongo query that I would look like to see is this (actual guid syntax is not correct, but the left side is the important part:

{ "S.I": "99ebc751-c12a-4873-8c3f-cb510b26a082" }

How do I do this?

4

1 回答 1

0

您需要按照 Nuk Nuk 在对您的问题的评论中提到的那样进行操作。或者,您可以使用 ElemMatch (docs.mongodb.org/manual/reference/operator/elemMatch),这可能更合适。

如果您对我们如何使用类型化语法支持这一点有任何建议,请提供一些反馈。出于同样的原因,我们正在努力解决如何支持位置 ($) 更新运算符。

于 2013-03-06T18:43:29.760 回答