I have this POCO classes
class Author
{
public int Id { get; set; }
public string Name { get; set; }
public bool Sex { get; set; }
}
class Book
{
public int Id { get; set; }
public string Title { get; set; }
public List<Author> Authors { get; set; }
}
How can I query the "Authors" prop to find, for example, all books written by an author?
I have tried many syntax but anythings work.
@mbdavid (I think my problem is how to inspect all elements in the list in order to retrieve the matched condition)
var Books = DB.GetCollection<Book>("Books");
var Query= Books.Find(Query.And(Query.Not("Authors",BsonValue.Null),Query.EQ("Authors[*].Name","Shakespeare")));
I haven't tested it by it should work.
Most helpful comment
var Books = DB.GetCollection<Book>("Books");var Query= Books.Find(Query.And(Query.Not("Authors",BsonValue.Null),Query.EQ("Authors[*].Name","Shakespeare")));I haven't tested it by it should work.