我必须收集,让我们说ColA
和ColB
:
public sealed class ColA : IDatabaseObject
{
[BsonId]
public Guid Id { get; set; }
[BsonElement("colb_id")]
public Guid ColB_Id { get; set; }
}
public sealed class ColB : IDatabaseObject
{
[BsonId]
public Guid Id { get; set; }
[BsonElement("title")]
public string Title { get; set; }
}
我需要在一个投影Proj
ColA
的结果,并通过ColA
中的ColB_Id
获得ColB
的标题,但我不能做到这一点,有一种方法,而不是在2个单独的查询?
public sealed class Proj
{
public Guid Id { get; set; }
public Guid Colb_Id { get; set; }
public string OtherTitleName { get; set; }
}
this.db.GetCollection<ColA>()
.Aggregate()
.Lookup<ColA, ColB, Proj>(
this.db.GetCollection<ColB>(),
a => a.ColB_Id,
b => b.Id,
// I need something like...
a => new Proj {
Id = a.Id,
ColB_Id = a.ColB_Id,
OtherTitleName = b.Title
}
)
查找是解决方案,还是我真的需要分两步完成?
1条答案
按热度按时间aij0ehis1#