Back to Catalog
Note that the value object referred to here is in the MongoDB entity class, not the value object in DDD , however, the two are also related, that is, it is a complement to the class, itself does not have the value of existence , and in the value object, but also do not need to have a primary key ID, This is also the same as DDD, it is understandable, because it is only a supplementary description of the main object, there is no sense of their own, so there is no use of the primary key, hehe.
Look at a MongoDB value object contact
Public classPerson { PublicPerson () { contact=Newtest.contact (); Addlist=NewList<test.address>(); Id=MongoDB.Bson.ObjectId.GenerateNewId (). ToString (); } [Bsonid] [Bsonrepresentation (Bsontype.objectid)] Public stringId {Get;Set; } Public stringName {Get;Set; } PublicDateTime Lastcontact {Get;Set; } PublicDateTime Birthday {Get;Set; } Public intAge {Get;Set; } PublicAddress Address {Get;Set; } PublicList<address> Addlist {Get;Set; } /// <summary> ///Value Object/// </summary> PublicContact {Get;Set; } }
Public class Contact { publicstringgetset;} Public string Get Set ; } Public string Get Set ; } }
You see the contact in person is a value object, it does not have an ID, it is just a supplement to people, that is, it is a way of contacting the encapsulation, note that in the MongoDB entity, when establishing the main object, it is necessary to assign values to the value object and the relationship object, which is required, of course, after the assignment, The value of the value object is null, which is also normal and necessary, if not for it
Assignment, then MongoDB is not going to let you go to update (C # driver is like this)
When assigning values to a value object, we can assign values by field, assign values by object, assign values by object, and overwrite the original object!
vare1 = Repository1. Find ("556e8f2c2683c8105c9e501f"); E1. Name="Wet"; E1. Contact.postcode="100001";//Assigning a value to a fieldE1. Contact =NewContact {Email ="[email protected]"};//assign a value to an entity, the original entity is overwrittenRepository1. Update (E1);
The result of the update, only the email field has a value, the other fields are overwritten, this is normal
MongoDB waits for everyone to explore, research ...
Back to Catalog
MongoDB Learning note ~mongodb value objects in an entity