2 回答
TA贡献1850条经验 获得超11个赞
我建议你试试这个:
var messageIds = new HashSet<string>(collection_B.Select(x => x.MessageId).Distinct()); List<string> list = collection_A .Where(c => messageIds.Contains(c.Id)) .Select(c => c.Id) .ToList();
TA贡献1865条经验 获得超7个赞
如果我正确理解您的问题,以下代码将为您指明正确的方向。我使用 MongoDAL 进行数据访问,这只是 c# 驱动程序的抽象。
using System;
using System.Linq;
using MongoDAL;
namespace Example
{
class Person : Entity
{
public string Name { get; set; }
}
class BanRecord : Entity
{
public One<Person> Person { get; set; }
public string ReasonForBan { get; set; }
}
class Program
{
static void Main(string[] args)
{
new DB("testdatabase");
var person1 = new Person { Name = "Person One" };
var person2 = new Person { Name = "Person Two" };
var person3 = new Person { Name = "Person Three" };
person1.Save();
person2.Save();
person3.Save();
var ban1 = new BanRecord
{
Person = person1.ToReference(),
ReasonForBan = "Cause we can!"
};
ban1.Save();
var ban2 = new BanRecord
{
Person = person2.ToReference(),
ReasonForBan = "Cause we can!"
};
ban2.Save();
var bannedPeople = (from b in DB.Collection<BanRecord>()
join p in DB.Collection<Person>() on b.Person.ID equals p.ID into banned
from p in banned
select p).ToArray();
Console.ReadKey();
}
}
}
- 2 回答
- 0 关注
- 75 浏览
添加回答
举报