Ejemplo n.º 1
0
        private static void ProcessManagedProperties(Type type, PersistanceTableInfo table, EntityMeta em)
        {
            foreach (var property in em.EntityProperties)
            {
                var meta = property.ColumnMeta;
                if (meta == null)
                {
                    continue;
                }

                var propertyName = property.Name;

                //生成 ManagedPropertyBridge
                var epm = em.Property(propertyName);
                if (epm == null)
                {
                    throw new ArgumentNullException(string.Format("{0}.{1} 属性需要使用托管属性进行编写。", type.FullName, propertyName));
                }


                var column = new PersistanceColumnInfo(epm, meta, table);

                if (meta.IsPrimaryKey)
                {
                    table.PKColumn = column;
                }

                table.Columns.Add(column);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 为某个指定的仓库对象构造一个 DbTable
        /// </summary>
        /// <param name="repo"></param>
        /// <returns></returns>
        internal static IPersistanceTableInfo CreateTableInfo(IRepositoryInternal repo)
        {
            var em = repo.EntityMeta;
            if (em.TableMeta == null)
            {
                throw new ORMException(string.Format("类型 {0} 没有映射数据库,无法为其创造 ORM 运行时对象。", em.EntityType.FullName));
            }

            var res = new PersistanceTableInfo(repo);

            ProcessManagedProperties(em.EntityType, res, em);

            return res;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 为某个指定的仓库对象构造一个 DbTable
        /// </summary>
        /// <param name="repo"></param>
        /// <returns></returns>
        internal static IPersistanceTableInfo CreateTableInfo(IRepositoryInternal repo)
        {
            var em = repo.EntityMeta;

            if (em.TableMeta == null)
            {
                throw new ORMException(string.Format("类型 {0} 没有映射数据库,无法为其创造 ORM 运行时对象。", em.EntityType.FullName));
            }

            var res = new PersistanceTableInfo(repo);

            ProcessManagedProperties(em.EntityType, res, em);

            return(res);
        }
Ejemplo n.º 4
0
 internal PersistanceColumnInfo(
     string name,
     EntityPropertyMeta propertyMeta,
     ColumnMeta columnMeta,
     PersistanceTableInfo table,
     DbTypeConverter dbTypeConverter
     )
 {
     this.Table        = table;
     this.Name         = name;
     this.Meta         = columnMeta;
     this.PropertyType = TypeHelper.IgnoreNullable(propertyMeta.PropertyType);
     this.DbType       = columnMeta.DbType ?? dbTypeConverter.FromClrType(this.PropertyType);
     this.Property     = propertyMeta.ManagedProperty as IProperty;
 }
Ejemplo n.º 5
0
        private static void ProcessManagedProperties(Type type, PersistanceTableInfo table, EntityMeta em)
        {
            foreach (var property in em.EntityProperties)
            {
                var meta = property.ColumnMeta;
                if (meta == null)
                {
                    continue;
                }

                var propertyName = property.Name;

                //生成 ManagedPropertyBridge
                var epm = em.Property(propertyName);
                if (epm == null)
                {
                    throw new ArgumentNullException(string.Format("{0}.{1} 属性需要使用托管属性进行编写。", type.FullName, propertyName));
                }
                var mp = epm.ManagedProperty as IProperty;

                //列名
                var columnName = meta.ColumnName;
                if (string.IsNullOrWhiteSpace(columnName))
                {
                    columnName = propertyName;
                }

                var column = new PersistanceColumnInfo
                {
                    Table        = table,
                    Name         = columnName,
                    DataType     = epm.PropertyType,
                    IsIdentity   = meta.IsIdentity,
                    IsPrimaryKey = meta.IsPrimaryKey,
                    Property     = mp
                };

                if (meta.IsPrimaryKey)
                {
                    table.PKColumn = column;
                }

                table.Columns.Add(column);
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 为某个指定的仓库对象构造一个 DbTable
        /// </summary>
        /// <param name="repo"></param>
        /// <returns></returns>
        internal static IPersistanceTableInfo CreateTableInfo(IRepositoryInternal repo)
        {
            var em = repo.EntityMeta;

            if (em.TableMeta == null)
            {
                throw new ORMException(string.Format("类型 {0} 没有映射数据库,无法为其创造 ORM 运行时对象。", em.EntityType.FullName));
            }

            var dbSetting          = RdbDataProvider.Get(repo).DbSetting;
            var identifierProvider = DbMigrationProviderFactory.GetIdentifierProvider(dbSetting.ProviderName);
            var dbTypeConverter    = DbMigrationProviderFactory.GetDbTypeConverter(dbSetting.ProviderName);

            var name = identifierProvider.Prepare(repo.EntityMeta.TableMeta.TableName);
            var res  = new PersistanceTableInfo(name, repo);

            ProcessManagedProperties(em.EntityType, res, em, identifierProvider, dbTypeConverter);

            return(res);
        }
Ejemplo n.º 7
0
        private static void ProcessManagedProperties(Type type, PersistanceTableInfo table, EntityMeta em)
        {
            foreach (var property in em.EntityProperties)
            {
                var meta = property.ColumnMeta;
                if (meta == null) continue;

                var propertyName = property.Name;

                //生成 ManagedPropertyBridge
                var epm = em.Property(propertyName);
                if (epm == null) { throw new ArgumentNullException(string.Format("{0}.{1} 属性需要使用托管属性进行编写。", type.FullName, propertyName)); }
                var mp = epm.ManagedProperty as IProperty;

                //列名
                var columnName = meta.ColumnName;
                if (string.IsNullOrWhiteSpace(columnName)) columnName = propertyName;

                var column = new PersistanceColumnInfo
                {
                    Table = table,
                    Name = columnName,
                    DataType = epm.PropertyType,
                    IsIdentity = meta.IsIdentity,
                    IsPrimaryKey = meta.IsPrimaryKey,
                    Property = mp
                };

                if (meta.IsPrimaryKey)
                {
                    table.PKColumn = column;
                }

                table.Columns.Add(column);
            }
        }
Ejemplo n.º 8
0
        public PersistanceColumnInfo(EntityPropertyMeta propertyMeta, ColumnMeta columnMeta, PersistanceTableInfo table)
        {
            _propertyMeta = propertyMeta;
            _columnMeta   = columnMeta;
            this.Table    = table;

            this.DataType     = propertyMeta.PropertyType;
            this.IsIdentity   = columnMeta.IsIdentity;
            this.IsPrimaryKey = columnMeta.IsPrimaryKey;
            this.Property     = propertyMeta.ManagedProperty as IProperty;
        }