This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
Hi Guys, I have Person Entity and it has One to many Relationship with Skills Entity. So in my PersonViewModel I have SkillsEntity Property reference. AutoMapper is used to map PersonViewModel and Person In Step1 user comes in Adds Person and saves person In Step2 User retrieves previously inserted Person and adds skills to that person view model and saves the person object, sisnce skills are newly addes it nicely inserts skills collection into the database with person id reference. In Step3 user retrives the PersonViewModel object again and updates email address. In this scenario all the related skills collection from the database is getting deleted and reinserted. When I looked into this AutoMapper is created new Skills object the EntityState is set to New where as for Personobject Entitystate set to Modified. Is there any way in lightspeed to tell not to touch the unmodified child objects. |
|
|
This sounds like a mapping issue in your use of AutoMapper rather than LightSpeed based on how you have described it. If I am understanding correctly in Step 3 you are deleting the existing Skills (e.g. by clearing the collection) and then adding each Skill again (which will be new objects). If that is whats occurring then I would look at why this is being done since you clearly just want update the existing data so you should not need to delete anything. Presumably AutoMapper may just need some direction on how to locate the existing Skills objects rather than believing it needs to repopulate the collection.
|
|
|
HI Jeremy, In step3- I am not updated skills. I am just trying to update the email address that belongs to Person, at this point skills object collection is untouched. When I Automap the PersonViewModel back to Person Model The entity state of person is Modified and for skills object collection it is New. If I have one - one relationship between two entities, it is not the case. May be I am missing some thing some simple. Any suggestions are welcome Thanks |
|
|
Given the end result you are seeing the mapping process is clearly doing something to flush the existing collection of its instances and then add new equivalents in error. Im afraid I am not familiar with AutoMapper but it looks like you can control the mapping to scope what fields are going to be handled? e.g. http://stackoverflow.com/questions/3146606/automapper-exclude-fields - I would recommend you scope the mapping down to just what is needed, the "traversal" side of things appears to just be default behaviour for AutoMapper based on a quick read of its Github page but using a custom resolver as above then gives you the scope to start configuring the mapper to tune it for your specific needs.
|
|