Ejemplo n.º 1
0
        private IReadOnlyList <ColumnModification> GenerateColumnModifications()
        {
            var adding = EntityState == EntityState.Added;
            var columnModifications = new List <ColumnModification>();
            var srcType             = _values?.GetType();

            foreach (var property in _entry.EntityType.GetProperties())
            {
                var    propertyAnnotations = property.Relational();
                var    isKey = property.IsPrimaryKey();
                var    isConcurrencyToken = property.IsConcurrencyToken;
                var    isCondition        = !adding && (isKey || isConcurrencyToken);
                var    readValue          = _entry.IsStoreGenerated(property);
                var    writeValue         = false;
                object value = null;

                var srcProp = srcType?.GetProperty(property.Name);

                if (!readValue)
                {
                    var modified = false;

                    if (srcProp != null)
                    {
                        value = srcProp.GetValue(_values);
                        _entry.SetCurrentValue(property, value);
                        modified = true;
                    }

                    if (adding && property.BeforeSaveBehavior == PropertySaveBehavior.Save ||
                        property.AfterSaveBehavior == PropertySaveBehavior.Save && modified)
                    {
                        writeValue = true;
                    }
                }

                if (readValue || writeValue || isCondition)
                {
                    var columnModification = new ColumnModification(
                        _entry,
                        property,
                        propertyAnnotations,
                        () => GenerateParameterName(isCondition && isConcurrencyToken),
                        readValue && !_writeOnly,
                        writeValue,
                        isKey,
                        isCondition,
                        isConcurrencyToken);

                    columnModifications.Add(columnModification);
                }
            }

            return(columnModifications);
        }