Ejemplo n.º 1
0
        /// <summary>
        ///     Return the value of the specified field.
        /// </summary>
        /// <param name="i">The index of the field to find.</param>
        /// <returns>
        ///     The <see cref="T:System.Object" /> which will contain the field value upon return.
        /// </returns>
        public virtual object GetValue(int i)
        {
            if (i == -1)
            {
                return(DBNull.Value);
            }
            if (i >= _baseElement.Elements().Count())
            {
                return(DBNull.Value);
            }

            var name = GetName(i);

            var mapEntiysPropToSchema = _target.GetDbToLocalSchemaMapping(name);

            var firstOrDefault = _target.GetPropertiesEx().FirstOrDefault(s => s.Name == mapEntiysPropToSchema);

            if (firstOrDefault == null)
            {
                return(DBNull.Value);
            }

            var propertyType = firstOrDefault.PropertyType;
            var xElement     = _baseElement.Elements().ElementAt(i);

            if (xElement.HasElements)
            {
                return(xElement.ToString());
            }

            var type = DataConverterExtensions.ChangeType(xElement.Value, propertyType);

            return(type);
        }
Ejemplo n.º 2
0
        internal static string[] GetSchemaMapping(this DbClassInfoCache type)
        {
            if (IsAnonymousType(type))
            {
                return(type.GetPropertiesEx().Select(s => s.Name).ToArray());
            }

            return(type.LocalToDbSchemaMapping());
        }