使用C#mongodb

时间:2018-04-17 13:43:18

标签: c# mongodb linq lambda

我试图比较MongoDB C#中的两个集合这么多次,但我没有得到期望的结果。 这是我的代码。

UserDetails Collection

{
"_id" : ObjectId("585bc1b137bd32466cfe1472"),
"NTID" : "kram",
"FirstName" : "KRamesh"

}

{
"_id" : ObjectId("585bc1b137bd32466cfe1473"),
"NTID" : "raj",
"FirstName" : "Rajan"

}

ReportDetails Collection

{
"_id" : ObjectId("59d347c77ab9655380bdb452"),
"FaxID" : "123",
"CreatedBy" : "kram",
"CreatedDate" : ISODate("2017-10-03T08:14:18.323Z"),
"LastModifiedBy" : "kram",
"LastModifiedDate" : ISODate("2018-02-01T10:25:14.719Z")

}

{
"_id" : ObjectId("59d347c77ab9655380bdb453"),
"FaxID" : "124",
"CreatedBy" : "raj",
"CreatedDate" : ISODate("2017-10-03T08:14:18.323Z"),
"LastModifiedBy" : "kram",
"LastModifiedDate" : ISODate("2018-02-01T10:25:14.719Z")

}

BsonResult = Collection.Find(finalQuery).OrderByDescending(c => c[_SortBy]).Skip(Skip).Take(Take).ToList();

                        var details = (from report in BsonResult.AsQueryable()
                                       join user in CollectionUserDetails.AsQueryable()
                                          on report["CreatedBy"] equals user["NTID"]
                                          into joinedreport
                        select new
                        {  
                            joinedreportings = joinedreport
                        }).ToList();
  

我的期望结果看起来像

{
"_id" : ObjectId("59d347c77ab9655380bdb452"),
"FaxID" : "123",
"CreatedBy" : "KRamesh",
"CreatedDate" : ISODate("2017-10-03T08:14:18.323Z"),
"LastModifiedBy" : "KRamesh",
"LastModifiedDate" : ISODate("2018-02-01T10:25:14.719Z")

}

{
"_id" : ObjectId("59d347c77ab9655380bdb453"),
"FaxID" : "124",
"CreatedBy" : "Rajan",
"CreatedDate" : ISODate("2017-10-03T08:14:18.323Z"),
"LastModifiedBy" : "KRamesh",
"LastModifiedDate" : ISODate("2018-02-01T10:25:14.719Z")

}

  

请给我解决方案..

谢谢, 彩

0 个答案:

没有答案