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

Proxy attribute on properties?

    • Type: Icon: Task Task
    • Resolution: Won't Fix
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 1.0
    • Component/s: Feature Request
    • Labels:

      It would be great if I could mark a class with an attribute so that the C# driver knows it needs to load/fetch (a join) additional documents without having to hand code this each time:

      class Order
      {
      [BsonReference("db.users", "_id", "UserId)]
      public User User

      {get;set;}
      ...
      }

      - Or lazy loading -

      class Order
      {
      [BsonReference("db.users", "_id", "UserId)]
      public Reference<User> User {get;set;}

      ...
      }

      In both examples, I indicate that this Order class (that the driver knows about due to mappings) has a User property that I would like to be loaded each time an Order is loaded as well. Let the driver load this on my behalf.

      The first version would always load the property, the second would lazy load for me - accessing the order.User property would lazy load the proxy in the background (the driver would fetch the instance for me).

      I'd like to avoid having to use a 'DBRef' in this case because the relationship is obvious (its always going to be a User I want loaded, found in the db.users collection).

      I also want to avoid using the 'FollowReference' syntax because it means I can't just use order.User I need to put a UserId on the Order instance (which is a bit unclean) and would rather be able to access the object directly (while being aware its going to cost in terms of performance).

      Thoughts?

      • Andrew

            Assignee:
            craig.wilson@mongodb.com Craig Wilson
            Reporter:
            plasma Andrew Armstrong
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: