Пример #1
0
        /// <summary>
        /// Returns <see cref="IValueConverter"/> for specific column.
        /// </summary>
        public virtual IValueConverter?GetValueConverter(ColumnDescriptor columnDescriptor)
        {
            if (ValueConverter != null)
            {
                return(ValueConverter);
            }

            if (ConverterType == null)
            {
                return(null);
            }

            var dynamicConverter = (IValueConverter)TypeAccessor.GetAccessor(ConverterType).CreateInstance();

            return(dynamicConverter);
        }
Пример #2
0
        void SetColumn(ColumnAttribute attr)
        {
            if (attr.MemberName == null)
            {
                throw new LinqToDBException("The Column attribute of the '{0}' type must have MemberName.".Args(TypeAccessor.Type));
            }

            if (attr.MemberName.IndexOf('.') < 0)
            {
                var ex = TypeAccessor[attr.MemberName];
                var cd = new ColumnDescriptor(_mappingSchema, attr, ex);

                Columns.Add(cd);
                _columnNames.Add(attr.MemberName, cd);
            }
            else
            {
                var cd = new ColumnDescriptor(_mappingSchema, attr, new MemberAccessor(TypeAccessor, attr.MemberName));

                Columns.Add(cd);
                _columnNames.Add(attr.MemberName, cd);
            }
        }
Пример #3
0
        void Init(MappingSchema mappingSchema)
        {
            var ta = mappingSchema.GetAttribute <TableAttribute>(TypeAccessor.Type, a => a.Configuration);

            if (ta != null)
            {
                TableName    = ta.Name;
                SchemaName   = ta.Schema;
                DatabaseName = ta.Database;
                IsColumnAttributeRequired = ta.IsColumnAttributeRequired;
            }

            if (TableName == null)
            {
                TableName = TypeAccessor.Type.Name;

                if (TypeAccessor.Type.IsInterfaceEx() && TableName.Length > 1 && TableName[0] == 'I')
                {
                    TableName = TableName.Substring(1);
                }
            }

            var attrs = new List <ColumnAttribute>();

            foreach (var member in TypeAccessor.Members)
            {
                var aa = mappingSchema.GetAttribute <AssociationAttribute>(TypeAccessor.Type, member.MemberInfo, attr => attr.Configuration);

                if (aa != null)
                {
                    Associations.Add(new AssociationDescriptor(
                                         TypeAccessor.Type, member.MemberInfo, aa.GetThisKeys(), aa.GetOtherKeys(), aa.ExpressionPredicate, aa.Storage, aa.CanBeNull));
                    continue;
                }

                var ca = mappingSchema.GetAttribute <ColumnAttribute>(TypeAccessor.Type, member.MemberInfo, attr => attr.Configuration);

                if (ca != null)
                {
                    if (ca.IsColumn)
                    {
                        if (ca.MemberName != null)
                        {
                            attrs.Add(new ColumnAttribute(member.Name, ca));
                        }
                        else
                        {
                            var cd = new ColumnDescriptor(mappingSchema, ca, member);
                            Columns.Add(cd);
                            _columnNames.Add(member.Name, cd);
                        }
                    }
                }
                else if (
                    !IsColumnAttributeRequired && mappingSchema.IsScalarType(member.Type) ||
                    mappingSchema.GetAttribute <IdentityAttribute>(TypeAccessor.Type, member.MemberInfo, attr => attr.Configuration) != null ||
                    mappingSchema.GetAttribute <PrimaryKeyAttribute>(TypeAccessor.Type, member.MemberInfo, attr => attr.Configuration) != null)
                {
                    var cd = new ColumnDescriptor(mappingSchema, new ColumnAttribute(), member);
                    Columns.Add(cd);
                    _columnNames.Add(member.Name, cd);
                }
                else
                {
                    var caa = mappingSchema.GetAttribute <ColumnAliasAttribute>(TypeAccessor.Type, member.MemberInfo, attr => attr.Configuration);

                    if (caa != null)
                    {
                        if (Aliases == null)
                        {
                            Aliases = new Dictionary <string, string>();
                        }

                        Aliases.Add(member.Name, caa.MemberName);
                    }
                }
            }

            var typeColumnAttrs = mappingSchema.GetAttributes <ColumnAttribute>(TypeAccessor.Type, a => a.Configuration);

            foreach (var attr in typeColumnAttrs.Concat(attrs))
            {
                if (attr.IsColumn)
                {
                    SetColumn(attr, mappingSchema);
                }
            }
        }
Пример #4
0
 /// <summary>
 /// Check if object contains values that should be skipped.
 /// </summary>
 /// <param name="obj">The object to check.</param>
 /// <param name="entityDescriptor">The entity descriptor.</param>
 /// <param name="columnDescriptor">The column descriptor.</param>
 /// <returns><c>true</c> if object should be skipped for the operation.</returns>
 public override bool ShouldSkip(object obj, EntityDescriptor entityDescriptor, ColumnDescriptor columnDescriptor)
 {
     return(Values?.Contains(columnDescriptor.MemberAccessor.Getter(obj)) ?? false);
 }
Пример #5
0
        void SetColumn(ColumnAttribute attr)
        {
            if (attr.MemberName == null)
                throw new LinqToDBException("The Column attribute of the '{0}' type must have MemberName.".Args(TypeAccessor.Type));

            if (attr.MemberName.IndexOf('.') < 0)
            {
                var ex = TypeAccessor[attr.MemberName];
                var cd = new ColumnDescriptor(_mappingSchema, attr, ex);

                Columns.Add(cd);
                _columnNames.Add(attr.MemberName, cd);
            }
            else
            {
                var cd = new ColumnDescriptor(_mappingSchema, attr, new MemberAccessor(TypeAccessor, attr.MemberName));

                Columns.Add(cd);
                _columnNames.Add(attr.MemberName, cd);
            }
        }
Пример #6
0
        void Init()
        {
            var ta = _mappingSchema.GetAttribute<TableAttribute>(TypeAccessor.Type, a => a.Configuration);

            if (ta != null)
            {
                TableName                 = ta.Name;
                SchemaName                = ta.Schema;
                DatabaseName              = ta.Database;
                IsColumnAttributeRequired = ta.IsColumnAttributeRequired;
            }

            if (TableName == null)
            {
                TableName = TypeAccessor.Type.Name;

                if (TypeAccessor.Type.IsInterface && TableName.Length > 1 && TableName[0] == 'I')
                    TableName = TableName.Substring(1);
            }

            var attrs = new List<ColumnAttribute>();

            foreach (var member in TypeAccessor.Members)
            {
                var aa = _mappingSchema.GetAttribute<AssociationAttribute>(member.MemberInfo, attr => attr.Configuration);

                if (aa != null)
                {
                    Associations.Add(new AssociationDescriptor(
                        TypeAccessor.Type, member.MemberInfo, aa.GetThisKeys(), aa.GetOtherKeys(), aa.Storage, aa.CanBeNull));
                    continue;
                }

                var ca = _mappingSchema.GetAttribute<ColumnAttribute>(member.MemberInfo, attr => attr.Configuration);

                if (ca != null)
                {
                    if (ca.IsColumn)
                    {
                        if (ca.MemberName != null)
                        {
                            attrs.Add(new ColumnAttribute(member.Name, ca));
                        }
                        else
                        {
                            var cd = new ColumnDescriptor(_mappingSchema, ca, member);
                            Columns.Add(cd);
                            _columnNames.Add(member.Name, cd);
                        }
                    }
                }
                else if (
                    !IsColumnAttributeRequired && _mappingSchema.IsScalarType(member.Type) ||
                    _mappingSchema.GetAttribute<IdentityAttribute>  (member.MemberInfo, attr => attr.Configuration) != null ||
                    _mappingSchema.GetAttribute<PrimaryKeyAttribute>(member.MemberInfo, attr => attr.Configuration) != null)
                {
                    var cd = new ColumnDescriptor(_mappingSchema, new ColumnAttribute(), member);
                    Columns.Add(cd);
                    _columnNames.Add(member.Name, cd);
                }
            }

            var typeColumnAttrs = _mappingSchema.GetAttributes<ColumnAttribute>(TypeAccessor.Type, a => a.Configuration);

            foreach (var attr in typeColumnAttrs.Concat(attrs))
                if (attr.IsColumn)
                    SetColumn(attr);
        }
Пример #7
0
 /// <summary>
 /// Check if object contains values that should be skipped.
 /// </summary>
 /// <param name="obj">The object to check.</param>
 /// <param name="entityDescriptor">The entity descriptor.</param>
 /// <param name="columnDescriptor">The column descriptor.</param>
 /// <returns><c>true</c> if object should be skipped for the operation.</returns>
 public abstract bool ShouldSkip(object obj, EntityDescriptor entityDescriptor, ColumnDescriptor columnDescriptor);