Note that there are some explanatory texts on larger screens.

plurals
  1. POMongo c# driver customize serialization for generic type
    text
    copied!<p>I have some issue with mongo c# driver. I have such class:</p> <pre><code>class MongoEntity&lt;T&gt; { public ObjectId Id {get; set;} public DateTime CreatedAt { get; set; } public DateTime UpdatedAt { get; set; } public int Version { get; set; } public T Entity { get; set; } } </code></pre> <p>And during serialization my entities to database I have such document:</p> <pre><code>"_id" : "510654cf33d22e1774d5a2a9", "CreatedAt" : { "DateTime" : ISODate("2013-01-28T10:37:02.932Z"), "Ticks" : NumberLong("634949662229321756") }, "UpdatedAt" : { "DateTime" : ISODate("2013-01-28T10:37:02.932Z"), "Ticks" : NumberLong("634949662229321756") }, "Version" : 1, "Entity" : { "EntityKey" : "tom@gmail.com", "Password" : "ICy5YqxZB1uWSwcVLSNLcA==", "Email" : "tom@gmail.com", "Name" : "Tom Anderson" } </code></pre> <p>What I really want is to have all properties of entity object in my document in the same level as properties of MongoEntity object like this:</p> <pre><code>"_id" : "510654cf33d22e1774d5a2a9", "CreatedAt" : { "DateTime" : ISODate("2013-01-28T10:37:02.932Z"), "Ticks" : NumberLong("634949662229321756") }, "UpdatedAt" : { "DateTime" : ISODate("2013-01-28T10:37:02.932Z"), "Ticks" : NumberLong("634949662229321756") }, "Version" : 1, "EntityKey" : "tom@gmail.com", "Password" : "ICy5YqxZB1uWSwcVLSNLcA==", "Email" : "tom@gmail.com", "Name" : "Tom Anderson" </code></pre> <p>without Entity embedded object. How can I implement this in easiest way ?</p> <p>P.S. What I am really looking for is some configuration of driver or writing custom serializer, maybe some workaround with dynamic, I do not want to change current class structure Enteties &lt;-> MongoEntity</p> <p>Thx for help. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload