GetValue() public abstract method

public abstract GetValue ( int i ) : object
i int
return object
示例#1
0
        /// <summary>
        ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to
        ///     the same compatibility standards as public APIs. It may be changed or removed without notice in
        ///     any release. You should only use it directly in your code with extreme caution and knowing that
        ///     doing so can result in application failures when updating to a new Entity Framework Core release.
        /// </summary>
        public static T GetValueOrDefault <T>([NotNull] this DbDataRecord record, [NotNull] string name)
        {
            var idx = record.GetOrdinal(name);

            return(record.IsDBNull(idx)
                ? default
                : (T)record.GetValue(idx));
        }
        public static void AuditEntityDeleted(AuditEntry entry, DbDataRecord record, string prefix = "")
        {
            for (var i = 0; i < record.FieldCount; i++)
            {
                var name = record.GetName(i);
                var value = record.GetValue(i);

                var valueRecord = value as DbDataRecord;
                if (valueRecord != null)
                {
                    // Complex Type
                    AuditEntityDeleted(entry, valueRecord, string.Concat(prefix, name, "."));
                }
                else
                {
                    entry.Properties.Add(new AuditEntryProperty(string.Concat(prefix, name), value, null));
                }
            }
        }
        public static void AuditEntityModified(Audit audit, AuditEntry entry, DbDataRecord orginalRecord, DbUpdatableDataRecord currentRecord, string prefix = "")
        {
            for (var i = 0; i < orginalRecord.FieldCount; i++)
            {
                var name = orginalRecord.GetName(i);
                var originalValue = orginalRecord.GetValue(i);
                var currentValue = currentRecord.GetValue(i);

                var valueRecord = originalValue as DbDataRecord;
                if (valueRecord != null)
                {
                    // Complex Type
                    AuditEntityModified(audit, entry, valueRecord, currentValue as DbUpdatableDataRecord, string.Concat(prefix, name, "."));
                }
                else
                {
                    if (audit.Configuration.IncludePropertyUnchanged || !Equals(currentValue, originalValue))
                    {
                        entry.Properties.Add(new AuditEntryProperty(string.Concat(prefix, name), originalValue, currentValue));
                    }
                }
            }
        }
        private static object GetDisplayValue(AuditEntryState state, NavigationProperty navigationProperty, IMemberAccessor displayMember, DbDataRecord values)
        {
            if (values == null)
                return null;

            var association = navigationProperty.RelationshipType as AssociationType;
            if (association == null)
                return null;

            // only support first constraint
            var referentialConstraint = association.ReferentialConstraints.FirstOrDefault();
            if (referentialConstraint == null)
                return null;

            var toProperties = referentialConstraint
              .ToProperties
              .Select(p => p.Name)
              .ToList();

            var fromProperties = referentialConstraint
              .FromProperties
              .Select(p => p.Name)
              .ToList();

            // make sure key columns match
            if (fromProperties.Count != toProperties.Count)
                return null;

            var edmType = referentialConstraint
              .FromProperties
              .Select(p => p.DeclaringType)
              .FirstOrDefault();

            if (edmType == null)
                return null;

            var entitySet = state.ObjectContext.GetEntitySet(edmType.FullName);

            var sql = new StringBuilder();
            sql.Append("SELECT VALUE t.")
                .Append(displayMember.Name)
                .Append(" FROM ")
                .Append(entitySet.Name)
                .Append(" as t")
                .Append(" WHERE ");

            var parameters = new List<ObjectParameter>();
            for (int index = 0; index < fromProperties.Count; index++)
            {
                if (index > 0)
                    sql.Append(" AND ");

                string fromProperty = fromProperties[index];
                string toProperty = toProperties[index];
                var value = values.GetValue(toProperty);
                var name = "@" + fromProperty;

                sql.Append(" t.").Append(fromProperty);
                if (value != null)
                {
                    sql.Append(" == ").Append(name);
                    parameters.Add(new ObjectParameter(fromProperty, value));
                }
                else
                {
                    sql.Append(" is null");
                }
            }

            var q = state.ObjectContext.CreateQuery<object>(
                sql.ToString(),
                parameters.ToArray());

            return q.FirstOrDefault();
        }
        private static object GetDisplayValue(AuditEntryState state, NavigationProperty navigationProperty, IMemberAccessor displayMember, DbDataRecord values)
        {
            if (values == null)
                return null;

            var association = navigationProperty.RelationshipType as AssociationType;
            if (association == null)
                return null;

            // only support first constraint
            var referentialConstraint = association.ReferentialConstraints.FirstOrDefault();
            if (referentialConstraint == null)
                return null;

            var toProperties = referentialConstraint
              .ToProperties
              .Select(p => p.Name)
              .ToList();

            var fromProperties = referentialConstraint
              .FromProperties
              .Select(p => p.Name)
              .ToList();

            // make sure key columns match
            if (fromProperties.Count != toProperties.Count)
                return null;

            var edmType = referentialConstraint
              .FromProperties
              .Select(p => p.DeclaringType)
              .FirstOrDefault();

            if (edmType == null)
                return null;

            var eSql = string.Format("SELECT VALUE t FROM {0} AS t", edmType.Name);

            var q = state.ObjectContext.CreateQuery<object>(eSql);
            for (int index = 0; index < fromProperties.Count; index++)
            {
                string fromProperty = fromProperties[index];
                string toProperty = toProperties[index];

                var value = values.GetValue(toProperty);
                var predicate = string.Format("it.{0} == @{0}", fromProperty);
                var parameter = new ObjectParameter(fromProperty, value);

                q = q.Where(predicate, parameter);
            }
            q = q.SelectValue<object>("it." + displayMember.Name);

            return q.FirstOrDefault();
        }