コード例 #1
0
        private static void InsertOrUpdate <TEntity>(TEntity entity, DbSet <TEntity> dbSet,
                                                     ProductionDomainContext productionDomainContext) where TEntity : BaseEntity
        {
            TEntity foundEntity = dbSet.Find(entity.Id);

            if (foundEntity == null
                )
            // it's not in DB yet
            {
                productionDomainContext.Entry(entity).State = EntityState.Added;
                dbSet.Add(entity);
            }
            else
            // it's already in DB
            {
                CopyDbPropertiesTo(entity, foundEntity);
                productionDomainContext.Entry(foundEntity).State = EntityState.Modified;
                dbSet.Update(foundEntity);
            }
        }
コード例 #2
0
 private static void Insert <TEntity>(TEntity entity, DbSet <TEntity> dbSet,
                                      ProductionDomainContext productionDomainContext) where TEntity : BaseEntity
 {
     productionDomainContext.Entry(entity).State = EntityState.Added;
     dbSet.Add(entity);
 }