<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Wed Feb 07 21:36:43 UTC 2024

It is possible to restrict the fields that are returned in this document by specifying the 'field' parameter in your request.
For example, to request only the issue key and summary append 'field=key&field=summary' to the URL of your request.
-->
<rss version="0.92" >
<channel>
    <title>MongoDB Jira</title>
    <link>https://jira.mongodb.org</link>
    <description>This file is an XML representation of an issue</description>
    <language>en-us</language>    <build-info>
        <version>9.7.1</version>
        <build-number>970001</build-number>
        <build-date>13-04-2023</build-date>
    </build-info>


<item>
            <title>[CSHARP-401] Implementing custom IdMemberConvention and ElementNameConvention</title>
                <link>https://jira.mongodb.org/browse/CSHARP-401</link>
                <project id="10041" key="CSHARP">C# Driver</project>
                    <description>&lt;p&gt;When creating multiple instances of MongoCollection&amp;lt;T&amp;gt;, each representing separate database collections, it is possible to encounter naming collisions between classes in calling into custom IdMemberConvention and ElementNameConvention classes. The following code better illustrates my point.&lt;/p&gt;

&lt;p&gt;class A&lt;br/&gt;
{&lt;br/&gt;
     ObjectId Id &lt;/p&gt;
{ get; set; }&lt;br/&gt;
}&lt;br/&gt;
&lt;br/&gt;
class AB : A&lt;br/&gt;
{&lt;br/&gt;
     ObjectId ABId { get; set; }
&lt;p&gt;}&lt;/p&gt;

&lt;p&gt;public class IdMemberConvention : IIdMemberConvention&lt;br/&gt;
{&lt;br/&gt;
	private Dictionary&amp;lt;Type,string&amp;gt; _idMembers;&lt;/p&gt;

&lt;p&gt;	public IdMemberConvention ()&lt;/p&gt;
	{ 
		this._idMembers = new Dictionary&amp;lt;Type,string&amp;gt; ();
	}

&lt;p&gt;	public void SetIdMember (Type type, string name)&lt;/p&gt;
	{
		this._idMembers[type] = name;
	}

&lt;p&gt;	public string FindIdMember (Type type)&lt;br/&gt;
	{&lt;br/&gt;
		try&lt;/p&gt;
		{
			return this._idMembers[type];
		}
&lt;p&gt;		catch&lt;/p&gt;
		{
			return null;
		}
&lt;p&gt;	}&lt;br/&gt;
}&lt;/p&gt;

&lt;p&gt;For both classes A and AB I would call IdMemberConvention&apos;s SetIdMember method as follows, respectively; &lt;/p&gt;

&lt;p&gt;     SetIdMember(typeof(A), &quot;Id&quot;);&lt;br/&gt;
     SetIdMember(typeof(AB), &quot;ABId&quot;);&lt;/p&gt;

&lt;p&gt;However, this is problematic for me, as BsonClassMap calls &quot;FindIdMember&quot; in a recursive manner, such that the base-most class is first passed into &quot;FindIdMember&quot; and on up the type chain until a non-null value is returned. And so the &quot;FindIdMember&quot; method, in the case of type A, is called twice; first for base type System.Object and secondly for type A. Furthermore, type AB results in three calls to &quot;FindIdMember&quot; (assuming that the id property is not found in a base class) which are, respectively, types System.Object, A and AB. The problem arises in fetching the id member for type AB. Because AB extends class A, and I have set the id member for type A (i.e. SetIdMember(typeof(A), &quot;Id&quot;)) as well as for type AB, &quot;FindIdMember&quot; would return &quot;Id&quot; instead of the expected &quot;ABId&quot;.&lt;/p&gt;

&lt;p&gt;A solution to this problem, and one I&apos;ll quickly implement for my purposes, would be to send the collection type, AB in this example, to the &quot;FindIdMember&quot; method, so that I could distinguish a call to &quot;FindIdMember&quot; between types A and AB. What do you think of this solution? Is there a cleaner way to achieve this? Is my implementation pattern here all wrong?&lt;/p&gt;

&lt;p&gt;Thanks. I hope this is helpful.&lt;/p&gt;</description>
                <environment>Mono 2.10.8, OS X</environment>
        <key id="31126">CSHARP-401</key>
            <summary>Implementing custom IdMemberConvention and ElementNameConvention</summary>
                <type id="4" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14710&amp;avatarType=issuetype">Improvement</type>
                                            <priority id="3" iconUrl="https://jira.mongodb.org/images/icons/priorities/major.svg">Major - P3</priority>
                        <status id="6" iconUrl="https://jira.mongodb.org/images/icons/statuses/closed.png" description="The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.">Closed</status>
                    <statusCategory id="3" key="done" colorName="success"/>
                                    <resolution id="9">Done</resolution>
                                        <assignee username="robert@mongodb.com">Robert Stam</assignee>
                                    <reporter username="rposky">Robert Poskevich</reporter>
                        <labels>
                            <label>driver</label>
                    </labels>
                <created>Tue, 21 Feb 2012 17:35:04 +0000</created>
                <updated>Thu, 2 Apr 2015 18:27:31 +0000</updated>
                            <resolved>Tue, 21 Feb 2012 20:21:19 +0000</resolved>
                                    <version>1.3.1</version>
                                    <fixVersion>1.4</fixVersion>
                                    <component>Feature Request</component>
                                        <votes>0</votes>
                                    <watches>1</watches>
                                                                                                                <comments>
                            <comment id="90575" author="rstam" created="Tue, 21 Feb 2012 20:21:19 +0000"  >&lt;p&gt;I think it&apos;s OK for me to close this JIRA now. If you still have a pending issue please add a comment and reopen it.&lt;/p&gt;</comment>
                            <comment id="90523" author="rposky" created="Tue, 21 Feb 2012 18:16:04 +0000"  >&lt;p&gt;Ok, that&apos;s a great point.  I&apos;ve added an Exception to my IdMemberConvention that should prevent me from using it incorrectly. Thanks again.&lt;/p&gt;</comment>
                            <comment id="90517" author="rstam" created="Tue, 21 Feb 2012 18:01:43 +0000"  >&lt;p&gt;Here&apos;s a sample program testing your classes and convention:&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;http://www.pastie.org/3428513&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;http://www.pastie.org/3428513&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I set a breakpoint on FindIdMember in the custom convention and it is only called once for type A. Note that I only call SetIdMember on the convention for type A because only the root class can have an _id property.&lt;/p&gt;

&lt;p&gt;Note that the ABId property is treated like a regular data field and is not associated with the _id.&lt;/p&gt;</comment>
                            <comment id="90510" author="rstam" created="Tue, 21 Feb 2012 17:49:13 +0000"  >&lt;p&gt;In an inheritance hierarchy the _id element (whatever it is called in your POCO) must be a property of the root class.&lt;/p&gt;

&lt;p&gt;It looks like you want your AB class to have a different _id than the A class. If that&apos;s the case, then AB shouldn&apos;t derive from A.&lt;/p&gt;</comment>
                    </comments>
                    <attachments>
                    </attachments>
                <subtasks>
                    </subtasks>
                <customfields>
                                                                                                                                                                                                                                                                                                                                                                    <customfield id="customfield_15850" key="com.atlassian.jira.plugins.jira-development-integration-plugin:devsummary">
                        <customfieldname>Development</customfieldname>
                        <customfieldvalues>
                            
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    <customfield id="customfield_12550" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>2|hrh7xz:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10558" key="com.pyxis.greenhopper.jira:gh-global-rank">
                        <customfieldname>Rank (Obsolete)</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>14086</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            </customfields>
    </item>
</channel>
</rss>