Пример #1
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);
        }
Пример #2
0
        public static DataMapping GetMapping(Type type)
        {
            Assembly callingAssembly = DataContext.CallingAssembly;
            Dictionary <Type, DataMapping> mappings = null;

            if (callingAssembly == null)
            {
                mappings = _defaultMapping;
            }
            else
            {
                if (!_assemblyMapping.ContainsKey(callingAssembly))
                {
                    lock (_synobj)
                    {
                        if (!_assemblyMapping.ContainsKey(callingAssembly))
                        {
                            _assemblyMapping.Add(callingAssembly, new Dictionary <Type, DataMapping>());
                        }
                    }
                }
                mappings = _assemblyMapping[callingAssembly];
            }

            if (!mappings.ContainsKey(type))
            {
                lock (_synobj)
                {
                    if (!mappings.ContainsKey(type))
                    {
                        DataMapping mapping = CreateMapping(type);
                        mappings[type] = mapping;
                    }
                }
            }
            return(mappings[type]);
        }
Пример #3
0
 public DataFieldMapping(Type type, string fieldName, string indexName, DataMapping mapping, bool isNullable, string dbType)
     : base(type, fieldName, indexName, mapping, isNullable, dbType)
 {
 }