<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Wed Feb 07 21:36:42 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-396] BsonClassMap.AutoMap() does not incorporate inheritance.</title>
                <link>https://jira.mongodb.org/browse/CSHARP-396</link>
                <project id="10041" key="CSHARP">C# Driver</project>
                    <description>&lt;p&gt;Would you please explain why BsonClassMap.AutoMap() does not map inherited members? What might the possible side effects be of changing this in the source, if any.&lt;/p&gt;

&lt;p&gt;The changes I am considering are as follows:&lt;/p&gt;

&lt;ul class=&quot;alternate&quot; type=&quot;square&quot;&gt;
	&lt;li&gt;Removing any instances of BindingFlags.DeclaredOnly, namely in Bson =&amp;gt; Serialization =&amp;gt; Conventions =&amp;gt; MemberFinderConventions and Bson =&amp;gt; Serialization =&amp;gt; BsonClassMap&lt;/li&gt;
	&lt;li&gt;Removing check &quot;if (memberInfo.DeclaringType != _classType)&quot; and ensuing Exception in Bson =&amp;gt; Serialization =&amp;gt; BsonClassMap&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;Thanks for any help you can provide.&lt;/p&gt;</description>
                <environment>Mono 2.10.8 </environment>
        <key id="30893">CSHARP-396</key>
            <summary>BsonClassMap.AutoMap() does not incorporate inheritance.</summary>
                <type id="3" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14718&amp;avatarType=issuetype">Task</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>bson</label>
                            <label>driver</label>
                            <label>question</label>
                    </labels>
                <created>Fri, 17 Feb 2012 17:04:52 +0000</created>
                <updated>Fri, 5 Apr 2019 13:59:00 +0000</updated>
                            <resolved>Fri, 17 Feb 2012 17:10:01 +0000</resolved>
                                    <version>1.3.1</version>
                                    <fixVersion>1.4</fixVersion>
                                                        <votes>0</votes>
                                    <watches>1</watches>
                                                                                                                <comments>
                            <comment id="89627" author="rstam" created="Fri, 17 Feb 2012 22:13:34 +0000"  >&lt;p&gt;When registering class maps for an inheritance hierarchy you must register each class in the hierarchy separately. Each class map only maps the properties for that class; any inherited properties are handled by the class map for the class in which it is defined.&lt;/p&gt;

&lt;p&gt;The correct way to register the class maps for these two classes is:&lt;/p&gt;

&lt;p/&gt;
&lt;div id=&quot;syntaxplugin&quot; class=&quot;syntaxplugin&quot; style=&quot;border: 1px dashed #bbb; border-radius: 5px !important; overflow: auto; max-height: 30em;&quot;&gt;
&lt;table cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; border=&quot;0&quot; width=&quot;100%&quot; style=&quot;font-size: 1em; line-height: 1.4em !important; font-weight: normal; font-style: normal; color: black;&quot;&gt;
		&lt;tbody &gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;  margin-top: 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;BsonClassMap.RegisterClassMap&amp;lt;A&amp;gt;(cm =&amp;gt;&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;{&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;    cm.AutoMap();&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;    cm.SetIdMember(cm.GetMemberMap(a =&amp;gt; a.Id));&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;});&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   margin-bottom: 10px;  width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;BsonClassMap.RegisterClassMap&amp;lt;AB&amp;gt;();&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
			&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p/&gt;

&lt;p&gt;See also &lt;a href=&quot;https://jira.mongodb.org/browse/CSHARP-400&quot; title=&quot;Improve error message in SetIdMember when memberMap argument is for a different class&quot; class=&quot;issue-link&quot; data-issue-key=&quot;CSHARP-400&quot;&gt;&lt;del&gt;CSHARP-400&lt;/del&gt;&lt;/a&gt; which I have created for making the error message more descriptive.&lt;/p&gt;</comment>
                            <comment id="89510" author="rposky" created="Fri, 17 Feb 2012 17:59:11 +0000"  >&lt;p&gt;No, I am getting a runtime exception &quot;Invalid memberMap&quot; at Serialization =&amp;gt; BsonClassMap =&amp;gt; SetIdMember(BsonMemberMap memberMap). Because in my example, _declaredMemberMaps only contains &quot;b&quot; (and is looking for &quot;Id&quot;).&lt;/p&gt;

&lt;p&gt;You&apos;re right, that code wouldn&apos;t compile, and I apologize for being misleading. In reality, I am passing the Expression &quot;ab =&amp;gt; ab.Id&quot; to this method. I want to manually specify the primary key, which 9/10 will be the Bson ObjectId. The problem arises in that I generally store many Bson ObjectIds in my classes, and so I do not want to rely on the AutoMap to pick my primary key nor do I want to be rely on Bson Attributes (abstraction, in my case, is critical).&lt;/p&gt;

&lt;p&gt;Thanks for all your help thus far. Maybe this is another Mono issue.&lt;/p&gt;</comment>
                            <comment id="89496" author="rstam" created="Fri, 17 Feb 2012 17:43:11 +0000"  >&lt;p&gt;You are getting a compiler error, right? (since the compiler doesn&apos;t know if the generic type argument TType has an Id property or not).&lt;/p&gt;

&lt;p&gt;If you are not doing anything more than what you have shown I think you can just let the classes automap by themselves (which the driver does on demand if needed).&lt;/p&gt;</comment>
                            <comment id="89484" author="rposky" created="Fri, 17 Feb 2012 17:18:32 +0000"  >&lt;p&gt;So I am using the following code to map my class and to specify the primary key. My class structure is also provided below. This code fails for class type AB (TType = AB), as it fails to find member &quot;Id&quot;. Is there a better approach I should be using?&lt;/p&gt;

&lt;p&gt;        if(!BsonClassMap.IsClassMapRegistered(typeof(TType)))&lt;br/&gt;
	{&lt;br/&gt;
		BsonClassMap.RegisterClassMap&amp;lt;TType&amp;gt;(cm =&amp;gt; &lt;/p&gt;
{
			cm.AutoMap();
			cm.SetIdMember(cm.GetMemberMap(ab =&amp;gt; ab.Id));
		}
&lt;p&gt;);&lt;br/&gt;
	}&lt;/p&gt;

&lt;p&gt;        public class A&lt;br/&gt;
	{&lt;br/&gt;
		public ObjectId Id &lt;/p&gt;
{ get; set; }&lt;br/&gt;
		&lt;br/&gt;
		public int a { get; set; }
&lt;p&gt;	}&lt;/p&gt;

&lt;p&gt;	public class AB : A&lt;br/&gt;
	{&lt;br/&gt;
		public int b &lt;/p&gt;
{ get; set; }
&lt;p&gt;	}&lt;/p&gt;</comment>
                            <comment id="89477" author="rstam" created="Fri, 17 Feb 2012 17:09:48 +0000"  >&lt;p&gt;The fields and properties of the base class will be mapped when the base class is mapped. We don&apos;t want to map things twice.&lt;/p&gt;

&lt;p&gt;Each class in the class hierarchy is responsible for mapping only its own fields and properties.&lt;/p&gt;

&lt;p&gt;So class maps do incorporate inheritance, although perhaps in a slightly different way than you expected.&lt;/p&gt;</comment>
                            <comment id="89474" author="rposky" created="Fri, 17 Feb 2012 17:06:55 +0000"  >&lt;p&gt;&quot;Removing check &quot;&quot;if (memberInfo.DeclaringType != _classType)&quot;&quot; and ensuing Exception in Bson =&amp;gt; Serialization =&amp;gt; BsonClassMap&quot; should read as follows:&lt;/p&gt;

&lt;p&gt;Removing check &quot;if (memberInfo.DeclaringType != _classType)&quot; and ensuing Exception in Bson =&amp;gt; Serialization =&amp;gt; BsonClassMap =&amp;gt; MapMember(MemberInfo memberInfo)&lt;/p&gt;</comment>
                    </comments>
                <issuelinks>
                            <issuelinktype id="10012">
                    <name>Related</name>
                                            <outwardlinks description="related to">
                                        <issuelink>
            <issuekey id="30937">CSHARP-400</issuekey>
        </issuelink>
                            </outwardlinks>
                                                        </issuelinktype>
                    </issuelinks>
                <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|hrh7z3:</customfieldvalue>

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