Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Set class collection name
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  3 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Alex Brown  
View profile  
 More options Jul 16 2012, 7:30 am
From: Alex Brown <a...@alexjamesbrown.com>
Date: Mon, 16 Jul 2012 04:30:05 -0700 (PDT)
Local: Mon, Jul 16 2012 7:30 am
Subject: Set class collection name

By default, if I have a class called "MyClass" it is serialized into a
collection called "myclass"

Is there a way of overriding this in the BsonClassMap?
For example, an attribute on the class, or a Convention?

If not, I'm happy to fork this and try and implement.
Just don't want to double up...


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
craiggwilson  
View profile  
 More options Jul 16 2012, 8:23 am
From: craiggwilson <craiggwil...@gmail.com>
Date: Mon, 16 Jul 2012 05:23:09 -0700 (PDT)
Local: Mon, Jul 16 2012 8:23 am
Subject: Re: Set class collection name

That doesn't currently exist and you must specify this value everytime.
 There is a Jira for this feature:  
https://jira.mongodb.org/browse/CSHARP-126. It is important, vote it up or
leave a comment.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
NASAVIETNAM  
View profile  
 More options Jul 18 2012, 4:38 am
From: NASAVIETNAM <nasaviet...@gmail.com>
Date: Wed, 18 Jul 2012 01:38:00 -0700 (PDT)
Subject: Re: Set class collection name

[AttributeUsage(AttributeTargets.Class, Inherited = true)]
    public class CollectionName : Attribute
    {
        /// <summary>
        /// Initializes a new instance of the CollectionName class
attribute with the desired name.
        /// </summary>
        /// <param name="value">Name of the collection.</param>
        public CollectionName(string value)
        {
            if (string.IsNullOrWhiteSpace(value))
            {
                throw new ArgumentException("Empty collectionname not
allowed", "value");
            }

            Name = value;
        }

        /// <summary>
        /// Gets the name of the collection.
        /// </summary>
        /// <value>The name of the collection.</value>
        public string Name { get; private set; }
    }

//use

[CollectionName("myclass")]
public class MyClass
{

}

///

 public static string GetCollectionName<T>()
        {
            var _att = Attribute.GetCustomAttribute(typeof(T),
typeof(CollectionName));
            string _collectionName = _att != null ?
((CollectionName)_att).Name : typeof(T).Name;

            if (string.IsNullOrEmpty(_collectionName))
            {
                throw new ArgumentException("Collection name cannot be
empty for this entity");
            }
            return _collectionName;
        }


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »