private EntityEntry AddEntityEntry(EFEntityInfo entityInfo)
        {
            var entry = GetEntityEntry(entityInfo.Entity);

            if (entry.State == Microsoft.EntityFrameworkCore.EntityState.Detached)
            {
                return(DbContext.Add(entityInfo.Entity));
            }
            else
            {
                return(entry);
            }
        }
        private EntityEntry HandleModified(EFEntityInfo entityInfo)
        {
            var entry = AddEntityEntry(entityInfo);

            // EntityState will be changed to modified during the update from the OriginalValuesMap
            // Do NOT change this to EntityState.Modified because this will cause the entire record to update.
            entry.State = Microsoft.EntityFrameworkCore.EntityState.Unchanged;

            // updating the original values is necessary under certain conditions when we change a foreign key field
            // because the before value is used to determine ordering.
            UpdateOriginalValues(entry, entityInfo);

            //foreach (var dep in GetModifiedComplexTypeProperties(entity, metadata)) {
            //  entry.SetModifiedProperty(dep.Name);
            //}

            if (entry.State != Microsoft.EntityFrameworkCore.EntityState.Modified || entityInfo.ForceUpdate)
            {
                // _originalValusMap can be null if we mark entity.SetModified but don't actually change anything.
                entry.State = Microsoft.EntityFrameworkCore.EntityState.Modified;
            }
            return(entry);
        }
Esempio n. 3
0
 private ObjectStateEntry GetObjectStateEntry(EFEntityInfo entityInfo)
 {
     return(GetObjectStateEntry(entityInfo.Entity));
 }
Esempio n. 4
0
 private ObjectStateEntry AttachObjectStateEntry(EFEntityInfo entityInfo)
 {
     ObjectContext.AttachTo(entityInfo.EntitySetName, entityInfo.Entity);
     // Attach has lots of side effect - add has far fewer.
     return(GetObjectStateEntry(entityInfo));
 }
 private EntityEntry GetEntityEntry(EFEntityInfo entityInfo)
 {
     return(GetEntityEntry(entityInfo.Entity));
 }
 private EntityEntry AttachEntityEntry(EFEntityInfo entityInfo)
 {
     return(DbContext.Attach(entityInfo.Entity));
 }
 private EntityEntry GetOrAddEntityEntry(EFEntityInfo entityInfo)
 {
     return(AddEntityEntry(entityInfo));
 }