<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Wed Feb 07 21:37:23 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-630] Saving to Different Collection</title>
                <link>https://jira.mongodb.org/browse/CSHARP-630</link>
                <project id="10041" key="CSHARP">C# Driver</project>
                    <description>&lt;p&gt;I have the following model:&lt;/p&gt;

&lt;p&gt;    public class Account: Entity&lt;br/&gt;
    {&lt;br/&gt;
        public string Email&lt;/p&gt;
{ get; set; }&lt;br/&gt;
        public string Name { get; set; }
&lt;p&gt;        public string Designation &lt;/p&gt;
{ get; set; }&lt;br/&gt;
        public string Telephone { get; set; }
&lt;p&gt;        public string Mobile &lt;/p&gt;
{ get; set; }&lt;br/&gt;
        public string CompanyId { get; set; }
&lt;p&gt;    }&lt;/p&gt;

&lt;p&gt;    public class Store : Entity&lt;br/&gt;
    {        &lt;br/&gt;
        &lt;span class=&quot;error&quot;&gt;&amp;#91;Required&amp;#93;&lt;/span&gt;&lt;br/&gt;
        &lt;span class=&quot;error&quot;&gt;&amp;#91;DataMember&amp;#93;&lt;/span&gt;&lt;br/&gt;
        public string Name &lt;/p&gt;
{ get; set; }&lt;br/&gt;
        &lt;span class=&quot;error&quot;&gt;&amp;#91;Required&amp;#93;&lt;/span&gt;&lt;br/&gt;
        &lt;span class=&quot;error&quot;&gt;&amp;#91;DataMember&amp;#93;&lt;/span&gt;&lt;br/&gt;
        public string Address1 { get; set; }
&lt;p&gt;        &lt;span class=&quot;error&quot;&gt;&amp;#91;DataMember&amp;#93;&lt;/span&gt;&lt;br/&gt;
        public string Address2 &lt;/p&gt;
{ get; set; }&lt;br/&gt;
        &lt;span class=&quot;error&quot;&gt;&amp;#91;Required&amp;#93;&lt;/span&gt;&lt;br/&gt;
        &lt;span class=&quot;error&quot;&gt;&amp;#91;DataMember&amp;#93;&lt;/span&gt;&lt;br/&gt;
        public string City { get; set; }
&lt;p&gt;        &lt;span class=&quot;error&quot;&gt;&amp;#91;DataMember&amp;#93;&lt;/span&gt;&lt;br/&gt;
        &lt;span class=&quot;error&quot;&gt;&amp;#91;DisplayName(&amp;quot;State/Province&amp;quot;)&amp;#93;&lt;/span&gt;&lt;br/&gt;
        public string State &lt;/p&gt;
{ get; set; }&lt;br/&gt;
        &lt;span class=&quot;error&quot;&gt;&amp;#91;Required&amp;#93;&lt;/span&gt;&lt;br/&gt;
        &lt;span class=&quot;error&quot;&gt;&amp;#91;DataMember&amp;#93;&lt;/span&gt;&lt;br/&gt;
        public int Zip { get; set; }
&lt;p&gt;        &lt;br/&gt;
        &lt;span class=&quot;error&quot;&gt;&amp;#91;DataMember&amp;#93;&lt;/span&gt;&lt;br/&gt;
        public string CompanyId &lt;/p&gt;
{ get; set; }
&lt;p&gt;    }&lt;/p&gt;

&lt;p&gt;And the following repository: &lt;/p&gt;

&lt;p&gt;public class AccountRepository : MongoRepository&amp;lt;Account&amp;gt; , IAccountRepository {}&lt;/p&gt;

&lt;p&gt;public class StoreRepository : MongoRepository&amp;lt;Store&amp;gt;, IStoreRepository{}&lt;/p&gt;

&lt;p&gt;When i try to add an item to the account with the code below, an instance is also added to the store. What code be the cause of the store addition? I have debug my code to ensure that there are no call to StoreRepository add. Thanks in advance.&lt;/p&gt;

&lt;p&gt;                    AccountRepository repo = new AccountRepository();&lt;br/&gt;
                    repo.Add(new Got2FindMe.Infrastracture.Model.Account&lt;/p&gt;
                            {
                                Id = id,
                                Email = model.Email
                            }
&lt;p&gt;                        );&lt;/p&gt;</description>
                <environment>Windows 7</environment>
        <key id="56002">CSHARP-630</key>
            <summary>Saving to Different Collection</summary>
                <type id="1" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14703&amp;avatarType=issuetype">Bug</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="-1">Unassigned</assignee>
                                    <reporter username="williamtell">william tell</reporter>
                        <labels>
                    </labels>
                <created>Mon, 12 Nov 2012 10:47:41 +0000</created>
                <updated>Thu, 20 Mar 2014 14:36:04 +0000</updated>
                            <resolved>Wed, 14 Nov 2012 01:59:37 +0000</resolved>
                                                                                        <votes>0</votes>
                                    <watches>2</watches>
                                                                                                                <comments>
                            <comment id="188582" author="williamtell" created="Wed, 14 Nov 2012 01:21:33 +0000"  >&lt;p&gt;I see. This is a great info. Thank you very much.&lt;/p&gt;

&lt;p&gt;William&lt;/p&gt;
</comment>
                            <comment id="187793" author="craiggwilson" created="Tue, 13 Nov 2012 13:36:36 +0000"  >&lt;p&gt;If you look in the Util.cs class at &lt;a href=&quot;http://mongorepository.codeplex.com/SourceControl/changeset/view/20204#236959&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;http://mongorepository.codeplex.com/SourceControl/changeset/view/20204#236959&lt;/a&gt;, you&apos;ll find the problem.  There is a method at the bottom called GetCollectionNameFromType where it derives the collection name from your entity by it&apos;s type.  If it has a base type that is NOT Entity, it uses that.  Hence, when you insert a middle man (EntityBase), then all your types end up getting persisted in the same collection.&lt;/p&gt;

&lt;p&gt;You can use a &lt;span class=&quot;error&quot;&gt;&amp;#91;CollectionName&amp;#93;&lt;/span&gt; attribute on your classes (Store, Account, etc...) to set them to something you know.&lt;/p&gt;

&lt;p&gt;Hope that helps...&lt;/p&gt;</comment>
                            <comment id="187280" author="williamtell" created="Tue, 13 Nov 2012 01:38:31 +0000"  >&lt;p&gt;Hi Craig,&lt;/p&gt;

&lt;p&gt;That was a quick response. Thank you very much. I found the source of issue but I still don&#8217;t know what is happening. I am using Official MongoDb c# driver from NuGet (Version 1.6). The model I posted in your website was out of date, please see belew for the updated model. The error I encountered is that when I derived the Entity for my own entity base then inherit it for my model&apos;s, querying collections seem&apos;s to be having problem. When I removed the inheritance from my EntityBase and let the model inherit derictely from DreamSongs.MongoRepository&apos;s Entity, the error was gone and everything seems to be working good. &lt;/p&gt;

&lt;p&gt;   //Entity is from the DreamSongs.MongoRepository assembly &lt;br/&gt;
    public class EntityBase: Entity&lt;br/&gt;
    {&lt;br/&gt;
        public Status Status &lt;/p&gt;
{ get; set; }
&lt;p&gt;    }&lt;br/&gt;
   //erroneus &lt;br/&gt;
    public class Account: EntityBase&lt;/p&gt;
    {
        //codes here
    }&lt;br/&gt;
&lt;br/&gt;
   //erroneus&lt;br/&gt;
    public class Store : EntityBase&lt;br/&gt;
    {        
       //codes here
    }&lt;br/&gt;
  //working as expected&lt;br/&gt;
  //Entity was directly inherited&lt;br/&gt;
   public class Account: Entity&lt;br/&gt;
    {        //codes here    }
&lt;p&gt;  //working as expected&lt;br/&gt;
  //Entity was directly inherited&lt;br/&gt;
   public class Store : Entity&lt;/p&gt;
    {        
       //codes here
    }

&lt;p&gt;For now, I will stick to inheriting directly to the Entity. It will be good help if you can let me know what is happening. &lt;/p&gt;


&lt;p&gt;Again Thank you so much,&lt;br/&gt;
William&lt;/p&gt;
</comment>
                            <comment id="186431" author="craiggwilson" created="Mon, 12 Nov 2012 13:19:43 +0000"  >&lt;p&gt;Hi William,&lt;br/&gt;
  These types of questions are better posted at our google group here (&lt;a href=&quot;https://groups.google.com/forum/?fromgroups=#!forum/mongodb-user&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://groups.google.com/forum/?fromgroups=#!forum/mongodb-user&lt;/a&gt;) or on stackoverflow.com.&lt;/p&gt;

&lt;p&gt;  I this particular example, could you please let us know what a MongoRepository&amp;lt;T&amp;gt; is?  This is not a part of our driver and so some research will need to be conducted in order to help you with your problem.&lt;/p&gt;

&lt;p&gt;Thanks,&lt;br/&gt;
 Craig&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|hrkhr3:</customfieldvalue>

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