Exemple #1
0
        public ColumnAttribute GetEntityColumnAttribute(Type type, PropertyInfo proto)
        {
            ColumnAttribute attr = null;

            if (_orm.Aop.ConfigEntityProperty != null)
            {
                var aope = new Aop.ConfigEntityPropertyEventArgs(type, proto);
                _orm.Aop.ConfigEntityProperty(_orm, aope);
                attr = aope.ModifyResult;
            }
            if (attr == null)
            {
                attr = new ColumnAttribute();
            }
            if (dicConfigEntity.TryGetValue(type, out var trytb) && trytb._columns.TryGetValue(proto.Name, out var trycol))
            {
                if (!string.IsNullOrEmpty(trycol.Name))
                {
                    attr.Name = trycol.Name;
                }
                if (!string.IsNullOrEmpty(trycol.OldName))
                {
                    attr.OldName = trycol.OldName;
                }
                if (!string.IsNullOrEmpty(trycol.DbType))
                {
                    attr.DbType = trycol.DbType;
                }
                if (trycol._IsPrimary != null)
                {
                    attr._IsPrimary = trycol.IsPrimary;
                }
                if (trycol._IsIdentity != null)
                {
                    attr._IsIdentity = trycol.IsIdentity;
                }
                if (trycol._IsNullable != null)
                {
                    attr._IsNullable = trycol.IsNullable;
                }
                if (trycol._IsIgnore != null)
                {
                    attr._IsIgnore = trycol.IsIgnore;
                }
                if (trycol._IsVersion != null)
                {
                    attr._IsVersion = trycol.IsVersion;
                }
                if (trycol.MapType != null)
                {
                    attr.MapType = trycol.MapType;
                }
                if (trycol._Position != null)
                {
                    attr._Position = trycol.Position;
                }
                if (trycol._CanInsert != null)
                {
                    attr._CanInsert = trycol.CanInsert;
                }
                if (trycol._CanUpdate != null)
                {
                    attr._CanUpdate = trycol.CanUpdate;
                }
                if (trycol.ServerTime != DateTimeKind.Unspecified)
                {
                    attr.ServerTime = trycol.ServerTime;
                }
                if (trycol._StringLength != null)
                {
                    attr.StringLength = trycol.StringLength;
                }
                if (!string.IsNullOrEmpty(trycol.InsertValueSql))
                {
                    attr.InsertValueSql = trycol.InsertValueSql;
                }
            }
            var attrs = proto.GetCustomAttributes(typeof(ColumnAttribute), false);

            foreach (var tryattrobj in attrs)
            {
                var tryattr = tryattrobj as ColumnAttribute;
                if (tryattr == null)
                {
                    continue;
                }
                if (!string.IsNullOrEmpty(tryattr.Name))
                {
                    attr.Name = tryattr.Name;
                }
                if (!string.IsNullOrEmpty(tryattr.OldName))
                {
                    attr.OldName = tryattr.OldName;
                }
                if (!string.IsNullOrEmpty(tryattr.DbType))
                {
                    attr.DbType = tryattr.DbType;
                }
                if (tryattr._IsPrimary != null)
                {
                    attr._IsPrimary = tryattr.IsPrimary;
                }
                if (tryattr._IsIdentity != null)
                {
                    attr._IsIdentity = tryattr.IsIdentity;
                }
                if (tryattr._IsNullable != null)
                {
                    attr._IsNullable = tryattr.IsNullable;
                }
                if (tryattr._IsIgnore != null)
                {
                    attr._IsIgnore = tryattr.IsIgnore;
                }
                if (tryattr._IsVersion != null)
                {
                    attr._IsVersion = tryattr.IsVersion;
                }
                if (tryattr.MapType != null)
                {
                    attr.MapType = tryattr.MapType;
                }
                if (tryattr._Position != null)
                {
                    attr._Position = tryattr.Position;
                }
                if (tryattr._CanInsert != null)
                {
                    attr._CanInsert = tryattr.CanInsert;
                }
                if (tryattr._CanUpdate != null)
                {
                    attr._CanUpdate = tryattr.CanUpdate;
                }
                if (tryattr.ServerTime != DateTimeKind.Unspecified)
                {
                    attr.ServerTime = tryattr.ServerTime;
                }
                if (tryattr._StringLength != null)
                {
                    attr.StringLength = tryattr.StringLength;
                }
                if (!string.IsNullOrEmpty(tryattr.InsertValueSql))
                {
                    attr.InsertValueSql = tryattr.InsertValueSql;
                }
            }
            ColumnAttribute ret = null;

            if (!string.IsNullOrEmpty(attr.Name))
            {
                ret = attr;
            }
            if (!string.IsNullOrEmpty(attr.OldName))
            {
                ret = attr;
            }
            if (!string.IsNullOrEmpty(attr.DbType))
            {
                ret = attr;
            }
            if (attr._IsPrimary != null)
            {
                ret = attr;
            }
            if (attr._IsIdentity != null)
            {
                ret = attr;
            }
            if (attr._IsNullable != null)
            {
                ret = attr;
            }
            if (attr._IsIgnore != null)
            {
                ret = attr;
            }
            if (attr._IsVersion != null)
            {
                ret = attr;
            }
            if (attr.MapType != null)
            {
                ret = attr;
            }
            if (attr._Position != null)
            {
                ret = attr;
            }
            if (attr._CanInsert != null)
            {
                ret = attr;
            }
            if (attr._CanUpdate != null)
            {
                ret = attr;
            }
            if (attr.ServerTime != DateTimeKind.Unspecified)
            {
                ret = attr;
            }
            if (attr._StringLength != null)
            {
                ret = attr;
            }
            if (!string.IsNullOrEmpty(attr.InsertValueSql))
            {
                ret = attr;
            }
            if (ret != null && ret.MapType == null)
            {
                ret.MapType = proto.PropertyType;
            }
            return(ret);
        }
Exemple #2
0
        public ColumnAttribute GetEntityColumnAttribute(Type type, PropertyInfo proto)
        {
            ColumnAttribute attr = null;

            if (_orm.Aop.ConfigEntityProperty != null)
            {
                var aope = new Aop.ConfigEntityPropertyEventArgs(type, proto);
                _orm.Aop.ConfigEntityProperty(_orm, aope);
                attr = aope.ModifyResult;
            }
            if (attr == null)
            {
                attr = new ColumnAttribute();
            }
            if (dicConfigEntity.TryGetValue(type, out var trytb) && trytb._columns.TryGetValue(proto.Name, out var trycol))
            {
                if (!string.IsNullOrEmpty(trycol.Name))
                {
                    attr.Name = trycol.Name;
                }
                if (!string.IsNullOrEmpty(trycol.OldName))
                {
                    attr.OldName = trycol.OldName;
                }
                if (!string.IsNullOrEmpty(trycol.DbType))
                {
                    attr.DbType = trycol.DbType;
                }
                if (trycol._IsPrimary != null)
                {
                    attr._IsPrimary = trycol.IsPrimary;
                }
                if (trycol._IsIdentity != null)
                {
                    attr._IsIdentity = trycol.IsIdentity;
                }
                if (trycol._IsNullable != null)
                {
                    attr._IsNullable = trycol.IsNullable;
                }
                if (trycol._IsIgnore != null)
                {
                    attr._IsIgnore = trycol.IsIgnore;
                }
                if (trycol._IsVersion != null)
                {
                    attr._IsVersion = trycol.IsVersion;
                }
                if (trycol._Uniques != null)
                {
                    attr._Uniques = trycol._Uniques;
                }
                if (trycol.MapType != null)
                {
                    attr.MapType = trycol.MapType;
                }
                if (trycol.DbDefautValue != null)
                {
                    attr.DbDefautValue = trycol.DbDefautValue;
                }
            }
            var attrs = proto.GetCustomAttributes(typeof(ColumnAttribute), false);

            foreach (var tryattrobj in attrs)
            {
                var tryattr = tryattrobj as ColumnAttribute;
                if (tryattr == null)
                {
                    continue;
                }
                if (!string.IsNullOrEmpty(tryattr.Name))
                {
                    attr.Name = tryattr.Name;
                }
                if (!string.IsNullOrEmpty(tryattr.OldName))
                {
                    attr.OldName = tryattr.OldName;
                }
                if (!string.IsNullOrEmpty(tryattr.DbType))
                {
                    attr.DbType = tryattr.DbType;
                }
                if (tryattr._IsPrimary != null)
                {
                    attr._IsPrimary = tryattr.IsPrimary;
                }
                if (tryattr._IsIdentity != null)
                {
                    attr._IsIdentity = tryattr.IsIdentity;
                }
                if (tryattr._IsNullable != null)
                {
                    attr._IsNullable = tryattr.IsNullable;
                }
                if (tryattr._IsIgnore != null)
                {
                    attr._IsIgnore = tryattr.IsIgnore;
                }
                if (tryattr._IsVersion != null)
                {
                    attr._IsVersion = tryattr.IsVersion;
                }
                if (tryattr._Uniques != null)
                {
                    attr._Uniques = tryattr._Uniques;
                }
                if (tryattr.MapType != null)
                {
                    attr.MapType = tryattr.MapType;
                }
                if (tryattr.DbDefautValue != null)
                {
                    attr.DbDefautValue = tryattr.DbDefautValue;
                }
            }
            ColumnAttribute ret = null;

            if (!string.IsNullOrEmpty(attr.Name))
            {
                ret = attr;
            }
            if (!string.IsNullOrEmpty(attr.OldName))
            {
                ret = attr;
            }
            if (!string.IsNullOrEmpty(attr.DbType))
            {
                ret = attr;
            }
            if (attr._IsPrimary != null)
            {
                ret = attr;
            }
            if (attr._IsIdentity != null)
            {
                ret = attr;
            }
            if (attr._IsNullable != null)
            {
                ret = attr;
            }
            if (attr._IsIgnore != null)
            {
                ret = attr;
            }
            if (attr._IsVersion != null)
            {
                ret = attr;
            }
            if (attr._Uniques != null)
            {
                ret = attr;
            }
            if (attr.MapType != null)
            {
                ret = attr;
            }
            if (attr.DbDefautValue != null)
            {
                ret = attr;
            }
            if (ret != null && ret.MapType == null)
            {
                ret.MapType = proto.PropertyType;
            }
            return(ret);
        }
Exemple #3
0
        public ColumnAttribute GetEntityColumnAttribute(Type type, PropertyInfo proto)
        {
            var attr = new ColumnAttribute();

            foreach (var mp in _mappingPriorityTypes)
            {
                switch (mp)
                {
                case MappingPriorityType.Aop:
                    if (_orm.Aop.ConfigEntityPropertyHandler != null)
                    {
                        var aope = new Aop.ConfigEntityPropertyEventArgs(type, proto);
                        _orm.Aop.ConfigEntityPropertyHandler(_orm, aope);
                        var tryattr = aope.ModifyResult;
                        if (!string.IsNullOrEmpty(tryattr.Name))
                        {
                            attr.Name = tryattr.Name;
                        }
                        if (!string.IsNullOrEmpty(tryattr.OldName))
                        {
                            attr.OldName = tryattr.OldName;
                        }
                        if (!string.IsNullOrEmpty(tryattr.DbType))
                        {
                            attr.DbType = tryattr.DbType;
                        }
                        if (tryattr._IsPrimary != null)
                        {
                            attr._IsPrimary = tryattr.IsPrimary;
                        }
                        if (tryattr._IsIdentity != null)
                        {
                            attr._IsIdentity = tryattr.IsIdentity;
                        }
                        if (tryattr._IsNullable != null)
                        {
                            attr._IsNullable = tryattr.IsNullable;
                        }
                        if (tryattr._IsIgnore != null)
                        {
                            attr._IsIgnore = tryattr.IsIgnore;
                        }
                        if (tryattr._IsVersion != null)
                        {
                            attr._IsVersion = tryattr.IsVersion;
                        }
                        if (tryattr.MapType != null)
                        {
                            attr.MapType = tryattr.MapType;
                        }
                        if (tryattr._Position != null)
                        {
                            attr._Position = tryattr.Position;
                        }
                        if (tryattr._CanInsert != null)
                        {
                            attr._CanInsert = tryattr.CanInsert;
                        }
                        if (tryattr._CanUpdate != null)
                        {
                            attr._CanUpdate = tryattr.CanUpdate;
                        }
                        if (tryattr.ServerTime != DateTimeKind.Unspecified)
                        {
                            attr.ServerTime = tryattr.ServerTime;
                        }
                        if (tryattr._StringLength != null)
                        {
                            attr.StringLength = tryattr.StringLength;
                        }
                        if (!string.IsNullOrEmpty(tryattr.InsertValueSql))
                        {
                            attr.InsertValueSql = tryattr.InsertValueSql;
                        }
                        if (tryattr._Precision != null)
                        {
                            attr.Precision = tryattr.Precision;
                        }
                        if (tryattr._Scale != null)
                        {
                            attr.Scale = tryattr.Scale;
                        }
                        if (!string.IsNullOrEmpty(tryattr.RewriteSql))
                        {
                            attr.RewriteSql = tryattr.RewriteSql;
                        }
                        if (!string.IsNullOrEmpty(tryattr.RereadSql))
                        {
                            attr.RereadSql = tryattr.RereadSql;
                        }
                    }
                    break;

                case MappingPriorityType.FluentApi:
                    var baseTypes = new List <Type>();
                    var baseType  = type;
                    while (baseType != typeof(object) && baseType != null)
                    {
                        baseTypes.Add(baseType);
                        baseType = baseType.BaseType;
                    }
                    for (var a = baseTypes.Count - 1; a >= 0; a--)
                    {
                        var entityType = baseTypes[a];
                        if (dicConfigEntity.TryGetValue(entityType, out var trytb) && trytb._columns.TryGetValue(proto.Name, out var trycol))
                        {
                            if (!string.IsNullOrEmpty(trycol.Name))
                            {
                                attr.Name = trycol.Name;
                            }
                            if (!string.IsNullOrEmpty(trycol.OldName))
                            {
                                attr.OldName = trycol.OldName;
                            }
                            if (!string.IsNullOrEmpty(trycol.DbType))
                            {
                                attr.DbType = trycol.DbType;
                            }
                            if (trycol._IsPrimary != null)
                            {
                                attr._IsPrimary = trycol.IsPrimary;
                            }
                            if (trycol._IsIdentity != null)
                            {
                                attr._IsIdentity = trycol.IsIdentity;
                            }
                            if (trycol._IsNullable != null)
                            {
                                attr._IsNullable = trycol.IsNullable;
                            }
                            if (trycol._IsIgnore != null)
                            {
                                attr._IsIgnore = trycol.IsIgnore;
                            }
                            if (trycol._IsVersion != null)
                            {
                                attr._IsVersion = trycol.IsVersion;
                            }
                            if (trycol.MapType != null)
                            {
                                attr.MapType = trycol.MapType;
                            }
                            if (trycol._Position != null)
                            {
                                attr._Position = trycol.Position;
                            }
                            if (trycol._CanInsert != null)
                            {
                                attr._CanInsert = trycol.CanInsert;
                            }
                            if (trycol._CanUpdate != null)
                            {
                                attr._CanUpdate = trycol.CanUpdate;
                            }
                            if (trycol.ServerTime != DateTimeKind.Unspecified)
                            {
                                attr.ServerTime = trycol.ServerTime;
                            }
                            if (trycol._StringLength != null)
                            {
                                attr.StringLength = trycol.StringLength;
                            }
                            if (!string.IsNullOrEmpty(trycol.InsertValueSql))
                            {
                                attr.InsertValueSql = trycol.InsertValueSql;
                            }
                            if (trycol._Precision != null)
                            {
                                attr.Precision = trycol.Precision;
                            }
                            if (trycol._Scale != null)
                            {
                                attr.Scale = trycol.Scale;
                            }
                            if (!string.IsNullOrEmpty(trycol.RewriteSql))
                            {
                                attr.RewriteSql = trycol.RewriteSql;
                            }
                            if (!string.IsNullOrEmpty(trycol.RereadSql))
                            {
                                attr.RereadSql = trycol.RereadSql;
                            }
                        }
                    }
                    break;

                case MappingPriorityType.Attribute:
                    var attrs = proto.GetCustomAttributes(typeof(ColumnAttribute), false);
                    foreach (var tryattrobj in attrs)
                    {
                        var tryattr = tryattrobj as ColumnAttribute;
                        if (tryattr == null)
                        {
                            continue;
                        }
                        if (!string.IsNullOrEmpty(tryattr.Name))
                        {
                            attr.Name = tryattr.Name;
                        }
                        if (!string.IsNullOrEmpty(tryattr.OldName))
                        {
                            attr.OldName = tryattr.OldName;
                        }
                        if (!string.IsNullOrEmpty(tryattr.DbType))
                        {
                            attr.DbType = tryattr.DbType;
                        }
                        if (tryattr._IsPrimary != null)
                        {
                            attr._IsPrimary = tryattr.IsPrimary;
                        }
                        if (tryattr._IsIdentity != null)
                        {
                            attr._IsIdentity = tryattr.IsIdentity;
                        }
                        if (tryattr._IsNullable != null)
                        {
                            attr._IsNullable = tryattr.IsNullable;
                        }
                        if (tryattr._IsIgnore != null)
                        {
                            attr._IsIgnore = tryattr.IsIgnore;
                        }
                        if (tryattr._IsVersion != null)
                        {
                            attr._IsVersion = tryattr.IsVersion;
                        }
                        if (tryattr.MapType != null)
                        {
                            attr.MapType = tryattr.MapType;
                        }
                        if (tryattr._Position != null)
                        {
                            attr._Position = tryattr.Position;
                        }
                        if (tryattr._CanInsert != null)
                        {
                            attr._CanInsert = tryattr.CanInsert;
                        }
                        if (tryattr._CanUpdate != null)
                        {
                            attr._CanUpdate = tryattr.CanUpdate;
                        }
                        if (tryattr.ServerTime != DateTimeKind.Unspecified)
                        {
                            attr.ServerTime = tryattr.ServerTime;
                        }
                        if (tryattr._StringLength != null)
                        {
                            attr.StringLength = tryattr.StringLength;
                        }
                        if (!string.IsNullOrEmpty(tryattr.InsertValueSql))
                        {
                            attr.InsertValueSql = tryattr.InsertValueSql;
                        }
                        if (tryattr._Precision != null)
                        {
                            attr.Precision = tryattr.Precision;
                        }
                        if (tryattr._Scale != null)
                        {
                            attr.Scale = tryattr.Scale;
                        }
                        if (!string.IsNullOrEmpty(tryattr.RewriteSql))
                        {
                            attr.RewriteSql = tryattr.RewriteSql;
                        }
                        if (!string.IsNullOrEmpty(tryattr.RereadSql))
                        {
                            attr.RereadSql = tryattr.RereadSql;
                        }
                    }
                    break;
                }
            }
            ColumnAttribute ret = null;

            if (!string.IsNullOrEmpty(attr.Name))
            {
                ret = attr;
            }
            if (!string.IsNullOrEmpty(attr.OldName))
            {
                ret = attr;
            }
            if (!string.IsNullOrEmpty(attr.DbType))
            {
                ret = attr;
            }
            if (attr._IsPrimary != null)
            {
                ret = attr;
            }
            if (attr._IsIdentity != null)
            {
                ret = attr;
            }
            if (attr._IsNullable != null)
            {
                ret = attr;
            }
            if (attr._IsIgnore != null)
            {
                ret = attr;
            }
            if (attr._IsVersion != null)
            {
                ret = attr;
            }
            if (attr.MapType != null)
            {
                ret = attr;
            }
            if (attr._Position != null)
            {
                ret = attr;
            }
            if (attr._CanInsert != null)
            {
                ret = attr;
            }
            if (attr._CanUpdate != null)
            {
                ret = attr;
            }
            if (attr.ServerTime != DateTimeKind.Unspecified)
            {
                ret = attr;
            }
            if (attr._StringLength != null)
            {
                ret = attr;
            }
            if (!string.IsNullOrEmpty(attr.InsertValueSql))
            {
                ret = attr;
            }
            if (attr._Precision != null)
            {
                ret = attr;
            }
            if (attr._Scale != null)
            {
                ret = attr;
            }
            if (!string.IsNullOrEmpty(attr.RewriteSql))
            {
                ret = attr;
            }
            if (!string.IsNullOrEmpty(attr.RereadSql))
            {
                ret = attr;
            }
            if (ret != null && ret.MapType == null)
            {
                ret.MapType = proto.PropertyType;
            }
            return(ret);
        }