【发布时间】:2021-10-01 13:04:19
【问题描述】:
我有一个包含列表的产品模型,我需要找到该产品并根据语言对其进行过滤。
return Collection.Find(p => p.ProductValues.Where(pv => pv.Lang == lang)).toList();
我得到的错误是
Cannot implicitly convert type 'System.Collections.Generic.IEnumerable<TestMongodb.Entities.ProductValue>' to 'bool'
我的模型是
public class Product : BaseEntity
{
public Product(string price, string date, List<ProductValue> value) =>
(Price, Date, ProductValues) = (price, date, value);
public string Price { get; set; }
public string Date { get; set; }
[BsonElement("value")]
public List<ProductValue> ProductValues { get; set; }
}
和
public class ProductValue
{
public ProductValue(string lang, string name, string description) =>
(Lang, Name, Description) = (lang, name, description);
[BsonElement("lang")]
public string Lang { get; }
[BsonElement("name")]
public string Name { get; }
[BsonElement("description")]
public string Description { get; }
}
【问题讨论】:
-
我不完全理解您的问题。
Find返回匹配的第一个单个实例。你为什么要在单个实例上调用ToList?