public void InsertOrUpdate(T entity)
{
if (entity.Id == 0)
{
context.Set<T>().Add(entity);
}
else
{
var query = context.Set<T>().Find(entity.Id);
context.Entry(query).CurrentValues.SetValues(Entity);
}
//context.Entry(entity).State = entity.Id == 0 ?
// EntityState.Added : EntityState.Modified;
context.SaveChanges();
}
I have already researched the internet and found something more performative or Clean, if someone can help me with some library thank you right away.