1
I am creating a solution for the web in the Singlepageaplication (SPA) type made with Aspnetcore and I use the Entity Framework to make my CRUD in the SQL Server database. I am sure that the Entity Framework allows me to update only what to change in a class so I intend to structure my frontend so that it only sends the attributes to the server that have changed, for example:
Pessoa.Cs (the class with all attributes)
internal class Pessoa
{
public string primeiroNome { get; set; }
public string segundoNome { get; set; }
public int idade { get; set; }
public string cpf { get; set; }
// ... mais outros inúmeros campos
}
This class is used in mine controller
to receive the CRUD coming from the frontend being:
GET = SELECT | POST = INSERT | PUT = UPDATE | DELETE = DELETE
Personal controler.Cs (part of the control that receives ajax as an example)
internal class PessoaController
{
[HttpPut("/")]
internal IActionResult Update([FromBody] Pessoa pessoa)
{
// ... todo o tratamento que preciso para salvar no EF
}
}
Ajax request that is made from my frontend for the update (thinking of a simple call using jQuery as example)
(function(){
// exemplo de atualização só do nome da pessoa
var pessoa = { nome: 'teste 123' };
$.ajax({
method: 'put',
url: '/',
data: JSON.stringify(pessoa)
success: function(res){ console.log('success', res); },
error: function(res){ console.log('error', res); }
})
})();
My question is the following: how can I "configure" the Entityframework so that it always receives a class and, if the attribute is null it does not update it in the database? Is there any way to set this up?
Note: the intention of this is to reduce the load of data traffic between the frontend and the backend, so I could save resources on both sides.
Needs to be a solution using only EF?
– Jéf Bueno
my work is on the front-end and I am obliged to integrate the back-end library (the solution has desktop and web modules)...
– LeandroLuk