When I try to add a new object to a Context via AddOrUpdate Migrations method, I have the error "Object reference not set to an instance of an object." in Package Console when updating database.
So, I tried to do use simple Add instead and appears it worked.
Here is my Entity Class:
[Table("Sistema_TipoTela")]
public class TipoTela : TabelaBase
{
public TipoTela() { }
public TipoTela(int Codigo, string Descricao)
{
this.Codigo = Codigo;
this.Descricao = Descricao;
}
public int Codigo { get; set; }
public string Descricao { get; set; }
}
So, with this code I have error:
var tipo = new TipoTela()
{
Codigo = 1,
Descricao = "Teste"
};
_db.Sistema_TelaTipo.AddOrUpdate(o => o.Codigo, tipo);
...or this:
_db.Sistema_TelaTipo.AddOrUpdate(tipo);
And with this code it's ok:
var tipo = new TipoTela()
{
Codigo = 1,
Descricao = "Teste"
};
_db.Sistema_TelaTipo.Add(tipo);
However, I need use AddOrUpdate to specify an array with "Codigo" as key property.
Thanks for your help
Edit 1
Forgot to metion that "TabelaBase" class have Id property