[CSHARP-197] Proxy attribute on properties? Created: 10/Apr/11 Updated: 05/Apr/19 Resolved: 04/May/12 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | Feature Request |
| Affects Version/s: | 1.0 |
| Fix Version/s: | None |
| Type: | Task | Priority: | Major - P3 |
| Reporter: | Andrew Armstrong | Assignee: | Craig Wilson |
| Resolution: | Won't Fix | Votes: | 0 |
| Labels: | question | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||
| Description |
|
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 ... } - 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?
|
| Comments |
| Comment by Craig Wilson [ 04/May/12 ] |
|
Andrew, However, if you truly want this feature, you can implement a custom IBsonSerializer that generates the necessary code yourself using Castle's DynamicProxy, LinFu, or another proxy generating library. Craig |