Skip to main content
deleted 4 characters in body
Source Link
marc_s
  • 759.8k
  • 186
  • 1.4k
  • 1.5k

My current solution is as follows. - I want to know whether this is correct.

Inside a HttpPost action method, I have the following code:

- Case type is an entity., case variable is passed as a parameter into the action method.:

Case caseInRepository = 
        _unitOfWork.CaseRepository.FindById(case.Id);

caseInRepository.UpdateState(case);

_unitOfWork.CaseRepository.Update(caseInRepository);
_unitOfWork.CaseRepository.SaveChanges();

The UpdateState method maps the fields of the argument (which isare the edited fields) to the instance. Some fields are ignored, since they were not set in the view, and are null.

My question is, with entity frameworkEntity Framework, the _unitOfWork.CaseRepository.Update(caseInRepository);

_unitOfWork.CaseRepository.Update(caseInRepository);

line is not necessary, since entities are tracked. However, I am not sure if it is right to remove it, since not all data storagesstorage support change tracking. I am also not sure if it is right to call FindById to get the item from the datastore.

My current solution is as follows. I want to know whether this is correct.

Inside a HttpPost action method, I have the following code:

Case type is an entity. case variable is passed as a parameter into the action method.

Case caseInRepository = 
        _unitOfWork.CaseRepository.FindById(case.Id);

caseInRepository.UpdateState(case);

_unitOfWork.CaseRepository.Update(caseInRepository);
_unitOfWork.CaseRepository.SaveChanges();

The UpdateState method maps the fields of the argument (which is the edited fields) to the instance. Some fields are ignored, since they were not set in the view, and are null.

My question is, with entity framework, the _unitOfWork.CaseRepository.Update(caseInRepository); line is not necessary, since entities are tracked. However, I am not sure if it is right to remove it, since not all data storages support change tracking. I am also not sure if it is right to call FindById to get the item from the datastore.

My current solution is as follows - I want to know whether this is correct.

Inside a HttpPost action method, I have the following code - Case type is an entity, case variable is passed as a parameter into the action method:

Case caseInRepository = _unitOfWork.CaseRepository.FindById(case.Id);

caseInRepository.UpdateState(case);

_unitOfWork.CaseRepository.Update(caseInRepository);
_unitOfWork.CaseRepository.SaveChanges();

The UpdateState method maps the fields of the argument (which are the edited fields) to the instance. Some fields are ignored, since they were not set in the view, and are null.

My question is, with Entity Framework, the

_unitOfWork.CaseRepository.Update(caseInRepository);

line is not necessary, since entities are tracked. However, I am not sure if it is right to remove it, since not all data storage support change tracking. I am also not sure if it is right to call FindById to get the item from the datastore.

Source Link

How to update an entity when implementing DDD using the repository and unit of work patterns with ASP.NET MVC?

My current solution is as follows. I want to know whether this is correct.

Inside a HttpPost action method, I have the following code:

Case type is an entity. case variable is passed as a parameter into the action method.

Case caseInRepository = 
        _unitOfWork.CaseRepository.FindById(case.Id);

caseInRepository.UpdateState(case);

_unitOfWork.CaseRepository.Update(caseInRepository);
_unitOfWork.CaseRepository.SaveChanges();

The UpdateState method maps the fields of the argument (which is the edited fields) to the instance. Some fields are ignored, since they were not set in the view, and are null.

My question is, with entity framework, the _unitOfWork.CaseRepository.Update(caseInRepository); line is not necessary, since entities are tracked. However, I am not sure if it is right to remove it, since not all data storages support change tracking. I am also not sure if it is right to call FindById to get the item from the datastore.