Getting this error: another object with the same identifier value was already associated with the session: 27, object: xxx.Core.Event
Basically, I have view models that display from my poco and vice versa. Violation code here:
Mapper.CreateMap<EventsAddEditViewModel, Event>(); Event thisEvent = _eventRepository.GetById(viewModel.Id); thisEvent = Mapper.Map<EventsAddEditViewModel, Event>(viewModel); thisEvent.EventType = new EventType { Id = viewModel.EventTypeId }; ValidationResult result = _eventService.Save(thisEvent);
I basically load the event from the database, and then map the view model to this event and save. Otherwise, there are fields that are not displayed in the view (for example, dateCreated) that will not be saved properly.
Is there a way that NHibernate and AutoMapper can play well in this regard?
I am using OnePerRequestBehavior for my session provider.
source share