Пример #1
0
        /// <summary>
        /// 获取数据表映射图
        /// </summary>
        /// <param name="type">映射类型</param>
        /// <returns>数据表映射图</returns>
        public static DataTableEntityMapping GetTableMapping(Type type)
        {
            DataTableEntityMapping dataMapping = GetMapping(type) as DataTableEntityMapping;

            if (dataMapping == null)
            {
                throw new LightDataException(RE.TheDataMappingIsNotDataTableMapping);
            }
            else
            {
                return(dataMapping);
            }
        }
Пример #2
0
        /// <summary>
        /// 创建关系映射图
        /// </summary>
        /// <param name="type">映射类型</param>
        /// <returns>关系映射图</returns>
        private static DataMapping CreateMapping(Type type)
        {
            string      tableName     = null;
            string      extentParam   = null;
            bool        isEntityTable = true;
            DataMapping dataMapping   = null;

            IDataTableConfig config = ConfigManager.LoadDataTableConfig(type);

            if (config != null)
            {
                tableName     = config.TableName;
                extentParam   = config.ExtendParams;
                isEntityTable = config.IsEntityTable;
            }

            if (string.IsNullOrEmpty(tableName))
            {
                tableName = type.Name;
            }

            if (type.IsSubclassOf(typeof(DataTableEntity)))
            {
                dataMapping = new DataTableEntityMapping(type, tableName, true);
            }
            else if (type.IsSubclassOf(typeof(DataEntity)))
            {
                dataMapping = new DataEntityMapping(type, tableName, true);
            }
            else
            {
                if (!isEntityTable)
                {
                    dataMapping = new DataEntityMapping(type, tableName, false);
                }
                else
                {
                    dataMapping = new DataTableEntityMapping(type, tableName, false);
                }
            }
            dataMapping.ExtentParams = new ExtendParamsCollection(extentParam);
            return(dataMapping);
        }