I use the following method to update a given table:
public int alteraBem(tb_bens itemBem)
{
try
{
using (GestaoAtivoEntities db = new GestaoAtivoEntities())
{
var bem = db.tb_bens.Where(v => v.int_id_bem.Equals(itemBem.int_id_bem)).FirstOrDefault();
bem.txt_tag_rfid = itemBem.txt_tag_rfid;
bem.txt_codigo = itemBem.txt_codigo;
bem.txt_descricao = itemBem.txt_descricao;
bem.txt_modelo = itemBem.txt_modelo;
bem.int_id_local = itemBem.int_id_local;
bem.int_id_obra = itemBem.int_id_obra;
bem.int_id_proprietario = itemBem.int_id_proprietario;
..... aqui vão os campos restantes......
db.SaveChanges();
Would you like to create a method to match the contents of objects dynamically, without having to do it manually one by one, with reflection or something similar?
It may even seem more complicated to create a method than to move line by line, but would like something like IgualarConteúdo(origem, destino)
.
I'm using classes generated by EntityFramework through the database.