Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-669

Retrieve Many-to-Many Object collection vai ObjectId Array

    XMLWordPrintableJSON

Details

    • Icon: Improvement Improvement
    • Resolution: Done
    • Icon: Minor - P4 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

      { get; private set; }
      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

      { return _category_ids; }

      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>)

      Attachments

        Activity

          People

            Unassigned Unassigned
            erhwenkuo ErhWenKuo
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: