Um neue Projekte hinzuzufügen sollte man update ausführen

This commit is contained in:
Husky
2020-02-26 10:22:29 +01:00
parent 348e6a9f3f
commit 9457784293
7 changed files with 182 additions and 138 deletions

View File

@@ -2,6 +2,7 @@
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
@@ -74,7 +75,19 @@ namespace KanSan.Base
public void Update(TEntity entityToUpdate)
{
dbSet.Attach(entityToUpdate);
context.Entry(entityToUpdate).State = EntityState.Modified;
IDatabaseEntry x = (entityToUpdate as IDatabaseEntry);
if(x == null)
return;
if(x.ID.Equals(0))
{
// Scheint ein neuer Eintrag zu sein
context.Entry(entityToUpdate).State = EntityState.Added;
}
else
{
context.Entry(entityToUpdate).State = EntityState.Modified;
}
}
}
}