Example #1
0
 /// <summary>
 /// 构造函数.
 /// </summary>
 /// <param name="tableName"></param>
 /// <param name="xmlFileName"></param>
 /// <param name="configOptions"></param>
 /// <param name="primaryKeys"></param>
 public ModelMapAttribute(string tableName, string xmlFileName, ModelConfigOptions configOptions, params string[] primaryKeys)
 {
     _TableName     = tableName;
     _XmlFileName   = xmlFileName;
     _PrimaryKeys   = primaryKeys;
     _ConfigOptions = configOptions;
 }
Example #2
0
        /// <summary>
        ///  针对一个实体永久化操作。
        ///   整个业务对象的所有实体操作在业务类的层次中进行整合操作处理。
        /// </summary>
        /// <param name="db"></param>
        /// <param name="entity"></param>
        /// <param name="operationType"></param>
        /// <param name="propertys"></param>
        /// <returns></returns>
        public System.Data.Common.DbCommand[] GetDbCommand(Database db, BaseModel entity, OperationType operationType, string[] propertys)
        {
            ModelMappingInfo   mappingInfo  = AttMappingManager.Instance.GetModelMappingInfo(entity.GetType());
            ModelConfigOptions cfgOptions   = mappingInfo.ConfigOptions;
            BaseSqlGenerator   sqlGenerator = SqlGeneratorManager.GetSqlGenerator(cfgOptions, propertys);

            SqlString[] sqlStr = sqlGenerator.GenerateSql(entity.GetType(), operationType, propertys);
            List <System.Data.Common.DbCommand> cmds = new List <System.Data.Common.DbCommand>();

            foreach (SqlString s in sqlStr)
            {
                System.Data.Common.DbCommand dbCmd = PrepareExecuteCommand(db, entity, s);
                cmds.Add(dbCmd);
            }
            return(cmds.ToArray());
        }
Example #3
0
        /// <summary>
        /// 获取生成SQL 的操作对象。
        /// </summary>
        /// <param name="cfgOptions"></param>
        /// <param name="properties"></param>
        /// <returns></returns>
        public static BaseSqlGenerator GetSqlGenerator(ModelConfigOptions cfgOptions, string[] properties)
        {
            BaseSqlGenerator sqlGenerator = null;

            if ((cfgOptions & ModelConfigOptions.CreateSqlByXmlCfg) != 0)
            {
                if (_XmlSqlConfigObject == null)
                {
                    _XmlSqlConfigObject = new XmlConfigSqlGenerator();
                }

                sqlGenerator = _XmlSqlConfigObject;
            }
            else
            {
                if (_AutoSqlCreate == null)
                {
                    _AutoSqlCreate = new AutoMappingSqlGenerator();
                }

                sqlGenerator = _AutoSqlCreate;
            }
            //如果存在个性化的属性,那么只能通过自动生成SQL 的方式。
            if (properties != null && properties.Length > 0)
            {
                if (_AutoSqlCreate == null)
                {
                    _AutoSqlCreate = new AutoMappingSqlGenerator();
                }

                return(_AutoSqlCreate);
            }
            else
            {
                return(sqlGenerator);
            }
        }
Example #4
0
 /// <summary>
 /// 获取生成SQL 的操作对象
 /// </summary>
 /// <param name="cfgOptions"></param>
 /// <returns></returns>
 public static BaseSqlGenerator GetSqlGenerator(ModelConfigOptions cfgOptions)
 {
     return(GetSqlGenerator(cfgOptions, null));
 }