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
|
OK, this may seem obvious to you but for some reason it doesn't to me. I'm creating a WCF service that serves as the repository for several client applications. The client apps submit new entities to the service to be saved to the database. So far, so good. Say I have a Parent entity that has an associated Child entity. I want to save every new instance of a Parent entity that is submitted to the service, but for the Child entities I do not necessarily want to save every one that comes in. If an identical Child entity already exists in the database, I just want to reference the existing database record. On the client side, I create a new Child entity and attach it to the Parent. Than, in the service, I check to see if there is a Child already existing and supply the Id instead of the entity. Here is an example from my service code: private void AddRefDeviceName(ref XmlDevice device, DeviceName deviceName) { if (null == deviceName) { throw new ArgumentNullException("deviceName", "DeviceName is a required entity"); } DeviceName existing = UnitOfWork.DeviceNames.DefaultIfEmpty(null).First(p => p.Name == deviceName.Name); if (null == existing) { device.DeviceName = new DeviceName { Name = deviceName.Name }; } else { device.DeviceNameId = existing.Id; } } |
|
|
Hi Dave, Can you post some details about the validation error? Assigning either the Id or the entity is fine as far as validation is concerned.
Jeremy |
|
|
OK, I must have been living in a twilight zone Friday. I spent over 3 hours verifying what I thought was causing my save to fail, then left you a message before I left for the day. Today, I can't make it fail... So, never mind, I guess. If I run into this again I'll reopen the issue. Dave |
|