如何使用C#查询MongoDB多位数子集合

时间:2019-07-08 09:25:01

标签: c# mongodb mongodb-.net-driver

我有一个多位数类别表,我想从该表中查询底部类别。

这样,我可以在查询时获得第一位数字,但不会带来低位数字

var query = Query<Category>.ElemMatch(x => x.SubCategories, builder => builder.EQ(actor => actor.IntegrationCategoryCode, categoryId));
var repository = new Data.MongoDB.Repository.MongoRepository<Category>();
var result= repository.CustomQuery(query).ToList();

[CollectionName("Category ")]
public class Category : Base.Entity
{
    [BsonElement("CategoryId")]
    public int CategoryId { get; set; }

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

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

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

    [BsonElement("Deleted")]
    [BsonRepresentation(BsonType.Boolean)]
    public bool Deleted { get; set; }

    [BsonElement("CreateDate")]
    [BsonDateTimeOptions(Kind = DateTimeKind.Utc)]
    public DateTime CreateDate { get; set; }

    [BsonElement("UpdateDate")]
    [BsonDateTimeOptions(Kind = DateTimeKind.Utc)]
    public DateTime UpdateDate { get; set; }

    public List<Category> SubCategories { get; set; }
}

0 个答案:

没有答案