I need to write objects to a table, knowing that I will only know in which table the object will be written at runtime.
For this I created a Dictionary with key and value defining the name of the field of the table and its value. However when I try to write this object in the bank I get error value cannot be null. r nparameter name entitytype
.
Dictionary<string, string> myobject = new Dictionary<string, string>();
myobject.Add("id_Lote", idLote.ToString());
myobject.Add("nr_Recuperacao", lote.nr_Recuperacao.ToString());
myobject.Add("id_Cliente", lote.id_Cliente);
myobject.Add("id_Produto", lote.id_Produto);
foreach (var item in loteDto.ItensCapaLote)
{
myobject.Add(item.id_ItemCapaLote.Replace(" ",""), item.valor);
}
public void NovoTipoCapaLote(dynamic myobject, string nameTable)
{
db.Set(nameTable).Add(myobject);
db.SaveChanges();
}