[CSHARP-126] New GetCollection<T>() signature that uses a default collection name based on the Type of collection (NORM migration suggestion) Created: 04/Dec/10 Updated: 03/Dec/20 Resolved: 03/Dec/20 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | Feature Request |
| Affects Version/s: | 0.7 |
| Fix Version/s: | None |
| Type: | New Feature | Priority: | Minor - P4 |
| Reporter: | Ian Mercer | Assignee: | Unassigned |
| Resolution: | Won't Do | Votes: | 7 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
Win 7, .NET 4, VS 2010 |
||
| Issue Links: |
|
||||||||
| Description |
|
If GetCollection<T> had a method that took no argument it would be easier for people to migrate from Norm to this driver. Simply construct a default collection name based on the type in use:- e.g. in MongoDatabase.cs public MongoCollection<TDefaultDocument> GetCollection<TDefaultDocument>() { string collectionName = typeof(TDefaultDocument).Name; return GetCollection<TDefaultDocument>(collectionName, safeMode); }This makes quick start / simple / common examples just a bit simpler and less error prone as there's no string value to get right. |
| Comments |
| Comment by Thomas Tucker [ 07/Jun/11 ] |
|
I like the approach of optional parameters for c# 4.0 support |
| Comment by Craig Wilson [ 13/Dec/10 ] |
|
This is a little more difficult than you would think. You have to take into account inheritance and how the name of the collection should (in most cases) stay the same. BTW: Robert, this is the particular case I was using when I submitted the "extensions" fork. We could do this outside the main API using an extension method if we could store items into both the convention profile as well as the BsonClassMap. |
| Comment by Gabriel Duford [ 06/Dec/10 ] |
|
What's done in https://github.com/mongodb-csharp/mongodb-csharp is very good. |