Я вставляю дочерние записи, которые связаны с существующей родительской записью. Как обновить родительскую запись, чтобы показать все, включая недавно вставленные дочерние записи?Обновить объект после дочерних записей, вставленных в linq в sql
context.Refresh(RefreshMode.OverwriteCurrentValues, entity)
не работает.
Более полный пример моей попытки:
Location newLocation = Json.deserialize<Location>(json);
if (newLocation != null) {
IEnumerable<string> zipCodes = Regex.Split(newLocation.zipCodes, @"[\s,;]+");
// this verifies the new zipcodes against a table of all US zipcodes and returns matches
var newLocationZipCodes = _zipCodeRepository.match(zipCodes).Select(item => new LocationZipCode { idLocation = newLocation.id, state = item.state, zipcode = item.zipcode });
// get the parent entity
var domainLocation = _unitOfWork.locationRepository.getFirst(l => l.id == newLocation.id);
// insert child entities
if (newLocationZipCodes.Any()) {
_unitOfWork.locationZipCodeRepository.insertAll(newLocationZipCodes);
_unitOfWork.saveChanges(ConflictMode.ContinueOnConflict);
}
// this isn't working
_unitOfWork.refresh(RefreshMode.OverwriteCurrentValues, domainLocation);
return domainLocation;
}
Вот основное представление класса LocationZipCode созданного LINQ-to-SQL:
public class LocationZipCode {
int idLocation;
string zipcode;
string state
EntityRef<Location> location;
}
А вот мой метод обновления в мой UnitOfWork:
public void refresh(RefreshMode refreshMode, object entity) {
_context.Refresh(refreshMode, entity);
}