Example #1
0
        private InitializedPocoDataBuilder BaseClassFalbackPocoDataBuilder(Type type)
        {
            var builder       = new PocoDataBuilder(type, _mapper).Init();
            var persistedType = builder.BuildTableInfo().PersistedType;

            if (persistedType == null || persistedType == type)
            {
                return(builder);
            }
            return(new PocoDataBuilder(persistedType, _mapper).Init());
        }
Example #2
0
        public static ColumnInfo FromMemberInfo(MemberInfo mi)
        {
            var ci = new ColumnInfo {
                MemberInfo = mi
            };
            var attrs                      = ReflectionUtils.GetCustomAttributes(mi).ToArray();
            var colAttrs                   = attrs.OfType <ColumnAttribute>().ToArray();
            var columnTypeAttrs            = attrs.OfType <ColumnTypeAttribute>().ToArray();
            var ignoreAttrs                = attrs.OfType <IgnoreAttribute>().ToArray();
            var complexMapping             = attrs.OfType <ComplexMappingAttribute>().ToArray();
            var serializedColumnAttributes = attrs.OfType <SerializedColumnAttribute>().ToArray();
            var reference                  = attrs.OfType <ReferenceAttribute>().ToArray();
            var aliasColumn                = attrs.OfType <AliasAttribute>().FirstOrDefault();

            // Check if declaring poco has [ExplicitColumns] attribute
            var explicitColumns = mi.DeclaringType.GetTypeInfo().GetCustomAttributes(typeof(ExplicitColumnsAttribute), true).Any();

            // Ignore column if declarying poco has [ExplicitColumns] attribute
            // and property doesn't have an explicit [Column] attribute,
            // or property has an [Ignore] attribute
            if ((explicitColumns && !colAttrs.Any() && !reference.Any() && !complexMapping.Any()) || ignoreAttrs.Any())
            {
                ci.IgnoreColumn = true;
            }

            if (complexMapping.Any())
            {
                ci.ComplexMapping = true;
                ci.ComplexPrefix  = complexMapping.First().CustomPrefix;
            }
            else if (mi.GetMemberInfoType().GetInterfaces().Any(x => x == typeof(IValueObject)))
            {
                ci.ValueObjectColumn = true;
            }
            else if (serializedColumnAttributes.Any())
            {
                ci.SerializedColumn = true;
            }
            else if (reference.Any())
            {
                ci.ReferenceType       = reference.First().ReferenceType;
                ci.ReferenceMemberName = reference.First().ReferenceMemberName ?? "Id";
                ci.ColumnName          = reference.First().ColumnName ?? mi.Name + "Id";
                return(ci);
            }
            else if (PocoDataBuilder.IsList(mi))
            {
                ci.ReferenceType = ReferenceType.Many;
                return(ci);
            }
            else if (mi.GetMemberInfoType().IsAClass() && !colAttrs.Any())
            {
                ci.ComplexMapping = true;
            }

            // Read attribute
            if (colAttrs.Any())
            {
                ci.ColumnName = colAttrs.FirstOrDefault(x => !string.IsNullOrEmpty(x.Name))?.Name ?? mi.Name;
                ci.ForceToUtc = colAttrs.All(x => x.ForceToUtc);

                var resultAttr = colAttrs.OfType <ResultColumnAttribute>().FirstOrDefault();
                ci.ResultColumn = resultAttr != null;

                if (!ci.ResultColumn)
                {
                    var versionAttr = colAttrs.OfType <VersionColumnAttribute>().FirstOrDefault();
                    ci.VersionColumn     = versionAttr != null;
                    ci.VersionColumnType = versionAttr?.VersionColumnType ?? ci.VersionColumnType;
                }

                if (!ci.VersionColumn && !ci.ResultColumn)
                {
                    var computedAttr = colAttrs.OfType <ComputedColumnAttribute>().FirstOrDefault();
                    ci.ComputedColumn     = computedAttr != null;
                    ci.ComputedColumnType = computedAttr?.ComputedColumnType ?? ComputedColumnType.Always;
                }
            }
            else
            {
                ci.ColumnName = mi.Name;
            }

            ci.ColumnAlias = aliasColumn?.Alias;

            if (columnTypeAttrs.Any())
            {
                ci.ColumnType = columnTypeAttrs.First().Type;
            }

            return(ci);
        }
Example #3
0
        public static ColumnInfo FromMemberInfo(MemberInfo mi)
        {
            var ci = new ColumnInfo {
                MemberInfo = mi
            };
            var attrs                      = ReflectionUtils.GetCustomAttributes(mi);
            var colAttrs                   = attrs.OfType <ColumnAttribute>();
            var columnTypeAttrs            = attrs.OfType <ColumnTypeAttribute>();
            var ignoreAttrs                = attrs.OfType <IgnoreAttribute>();
            var complexMapping             = attrs.OfType <ComplexMappingAttribute>();
            var serializedColumnAttributes = attrs.OfType <SerializedColumnAttribute>();
            var reference                  = attrs.OfType <ReferenceAttribute>();
            var aliasColumn                = attrs.OfType <AliasAttribute>().FirstOrDefault();

            // Check if declaring poco has [ExplicitColumns] attribute
            var explicitColumns = mi.DeclaringType.GetTypeInfo().GetCustomAttributes(typeof(ExplicitColumnsAttribute), true).Any();

            // Ignore column if declarying poco has [ExplicitColumns] attribute
            // and property doesn't have an explicit [Column] attribute,
            // or property has an [Ignore] attribute
            if ((explicitColumns && !colAttrs.Any()) || ignoreAttrs.Any())
            {
                ci.IgnoreColumn = true;
            }

            if (complexMapping.Any())
            {
                ci.ComplexMapping = true;
                ci.ComplexPrefix  = complexMapping.First().CustomPrefix;
            }
            else if (serializedColumnAttributes.Any())
            {
                ci.SerializedColumn = true;
            }
            else if (reference.Any())
            {
                ci.ReferenceType       = reference.First().ReferenceType;
                ci.ReferenceMemberName = reference.First().ReferenceMemberName ?? "Id";
                ci.ColumnName          = reference.First().ColumnName ?? mi.Name + "Id";
                return(ci);
            }
            else if (PocoDataBuilder.IsList(mi))
            {
                ci.ReferenceType = ReferenceType.Many;
                return(ci);
            }
            else if (mi.GetMemberInfoType().IsAClass() && !colAttrs.Any())
            {
                ci.ComplexMapping = true;
            }

            // Read attribute
            if (colAttrs.Any())
            {
                var colattr = colAttrs.First();
                ci.ColumnName         = colattr.Name ?? mi.Name;
                ci.ForceToUtc         = colattr.ForceToUtc;
                ci.ResultColumn       = colattr is ResultColumnAttribute;
                ci.VersionColumn      = colattr is VersionColumnAttribute;
                ci.VersionColumnType  = ci.VersionColumn ? ((VersionColumnAttribute)colattr).VersionColumnType : ci.VersionColumnType;
                ci.ComputedColumn     = colattr is ComputedColumnAttribute;
                ci.ComputedColumnType = ci.ComputedColumn ? ((ComputedColumnAttribute)colattr).ComputedColumnType : ComputedColumnType.Always;
            }
            else
            {
                ci.ColumnName = mi.Name;
            }

            ci.ColumnAlias = aliasColumn != null ? aliasColumn.Alias : null;

            if (columnTypeAttrs.Any())
            {
                ci.ColumnType = columnTypeAttrs.First().Type;
            }

            return(ci);
        }
Example #4
0
 private PocoDataBuilder BaseClassFalbackPocoDataBuilder(Type type)
 {
     var builder = new PocoDataBuilder(type, _mapper).Init();
     var persistedType = builder.BuildTableInfo().PersistedType;
     if (persistedType == null || persistedType == type)
     {
         return builder;
     }
     return new PocoDataBuilder(persistedType, _mapper).Init();
 }