Esempio n. 1
0
        public virtual TEntity GetAndCreate(TableSchema tableSchema)
        {
            if (_content == null)
            {
                throw new ArgumentNullException("tableSchema");
            }

            TEntity entity = EntityContext.Entities.ByTable(tableSchema.FullName);

            if (entity != null)
            {
                return(entity);
            }

            entity = new TEntity
            {
                FullName    = tableSchema.FullName,
                TableName   = tableSchema.Name,
                TableSchema = tableSchema.Owner
            };

            string className = _content.ToClassName(tableSchema.Name);

            className = _content.UniqueNamer.UniqueClassName(className);

            string mappingName = className + "Map";

            mappingName = _content.UniqueNamer.UniqueClassName(mappingName);

            string contextName = _content.Settings.ContextName(className);

            contextName = _content.ToPropertyName(EntityContext.ClassName, contextName);
            contextName = _content.UniqueNamer.UniqueContextName(contextName);

            entity.ClassName   = className;
            entity.ContextName = contextName;
            entity.MappingName = mappingName;

            _propertyTemplate.Entity = entity;

            foreach (ColumnSchema dataObjectBase in tableSchema.Columns.Selected())
            {
                // 过滤掉数据库自定义类型
                if (dataObjectBase.NativeType.Equals("hierarchyid", StringComparison.OrdinalIgnoreCase) ||
                    dataObjectBase.NativeType.Equals("sql_variant", StringComparison.OrdinalIgnoreCase))
                {
                    Debug.WriteLine("跳过字段 '{0}',因为目前不支持自定义类型'{1}'的处理.", dataObjectBase.Name, dataObjectBase.NativeType);
                    continue;
                }
                TProperty property = _propertyTemplate.GetAndCreate(dataObjectBase);
                entity.Properties.Add(property);
            }
            entity.Properties.IsProcessed = true;
            EntityContext.Entities.Add(entity);
            return(entity);
        }
Esempio n. 2
0
        public TEntity GetAndCreate(ViewSchema viewSchema)
        {
            if (_content == null)
            {
                throw new ArgumentNullException("viewSchema");
            }

            TEntity entity = EntityContext.Entities.ByTable(viewSchema.FullName);

            if (entity != null)
            {
                return(entity);
            }

            entity = new TEntity
            {
                FullName    = viewSchema.FullName,
                TableName   = viewSchema.Name,
                TableSchema = viewSchema.Owner
            };

            string className = _content.ToClassName(viewSchema.Name);

            className = _content.UniqueNamer.UniqueClassName(className);

            string mappingName = className + "Map";

            mappingName = _content.UniqueNamer.UniqueClassName(mappingName);

            string contextName = _content.Settings.ContextName(className);

            contextName = _content.ToPropertyName(EntityContext.ClassName, contextName);
            contextName = _content.UniqueNamer.UniqueContextName(contextName);

            entity.ClassName   = className;
            entity.ContextName = contextName;
            entity.MappingName = mappingName;

            entity.Properties = new PropertyCollection <TProperty>();

            PropertyTemplate <TEntity, TProperty> propertyTemplate = new PropertyTemplate <TEntity, TProperty>(_content)
            {
                Entity = entity
            };

            foreach (ViewColumnSchema dataObjectBase in viewSchema.Columns.Selected())
            {
                propertyTemplate.GetAndCreate(dataObjectBase);
            }

            EntityContext.Entities.Add(entity);

            return(entity);
        }