This question is locked. New answers and comments are not allowed.
I have a domain model and am passing our a list of objects that were created by Data Access
public List<batch.dal.Profile> ReadProfiles()
{
using (var dbContext = new batch.dal.dbContext())
{
return dbContext.Profiles.ToList();
}
}
The record is then modified on the client and when I save it as below the record is duplicated. The database key is a GUID and I have verified that the GUID is intact before the add. When the below is run it creates a duplicate
[WebInvoke(RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest)]
[OperationContract]
public bool UpdateProfile(batch.dal.Profile profile)
{
using (var dbContext = new batch.dal.dbContext())
{
dbContext.Add(profile);
dbContext.SaveChanges();
}
return true;
}
If I find the record by the Guid and then set that instance to the updated record, the save it ignored, even when I use the make dirty call. The only way I can find to update the record is to find the original record and then move each field from one object to the other and then save changes.
Is there an easier way of sending a class out in a webservice getting it back and then saving the data?
Thanks
Randy
public List<batch.dal.Profile> ReadProfiles()
{
using (var dbContext = new batch.dal.dbContext())
{
return dbContext.Profiles.ToList();
}
}
The record is then modified on the client and when I save it as below the record is duplicated. The database key is a GUID and I have verified that the GUID is intact before the add. When the below is run it creates a duplicate
[WebInvoke(RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest)]
[OperationContract]
public bool UpdateProfile(batch.dal.Profile profile)
{
using (var dbContext = new batch.dal.dbContext())
{
dbContext.Add(profile);
dbContext.SaveChanges();
}
return true;
}
If I find the record by the Guid and then set that instance to the updated record, the save it ignored, even when I use the make dirty call. The only way I can find to update the record is to find the original record and then move each field from one object to the other and then save changes.
Is there an easier way of sending a class out in a webservice getting it back and then saving the data?
Thanks
Randy