Details
-
Improvement
-
Resolution: Done
-
Minor - P4
-
None
-
1.7
-
None
-
None
Description
In order to do the many-to-many between tmpCategory & tmpProduct, I use a ObjectId list to store the which category that a product related to. When I get the "tmpProduct" object back from C# driver and would like to use "tmpProduct.Category_Ids" to retrieve the tmpCategory collection back utilize below method:
var categories = mongoCollection_Category.FindAs<tmpCategory>(Query.In("_id",product.Category_Ids));
=> C# complains that product.Category_Ids is not IEnumerable<BsonValue>??
=> However, the LINQ statement would work like below:
var categories2 = (from obj in mongoCollection_Category.AsQueryable<tmpCategory>()
where obj.Id.In(product.Category_Ids)
select obj).ToList<tmpCategory>();
public class tmpCategory
{
public ObjectId Id
public string Title { get; set; }
}
public class tmpProduct
{
private IList<ObjectId> _category_ids = new List<ObjectId>();
public ObjectId Id { get; private set; }
public string Name
{ get; set; } public IList<ObjectId> Category_Ids
{
get
set
{ _category_ids = value; } }
}
Would it be easier to have C# driver to add below methods?
1.Query.In("_id", IEnumerable<ObjectId>)
2.MongoCollection.FindAllByIdsAs(IEnumerable<ObjectId>)