コード例 #1
0
        /// <summary>
        /// 生成一条记录是否在数据库中存在
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="ob"></param>
        /// <returns></returns>
        public System.Data.IDbCommand GenerateExitsSql <T>(T ob)
        {
            var    TargetType = typeof(T);
            String TableName  = helper.GetTable(TargetType);
            var    Properties = TargetType.GetProperties();
            MSSQLScriptSqlPatternFactory factory = new MSSQLScriptSqlPatternFactory();

            System.Data.SqlClient.SqlCommand command = new System.Data.SqlClient.SqlCommand();
            String sql    = "Select  * From " + TableName + " Where  ";
            var    parity = factory.GetExistSql <T>(Properties, ob, false);

            command.Parameters.AddRange(parity.Params.ToArray());
            command.CommandText = sql + parity.SqlScript;
            return(command);
        }
コード例 #2
0
        public System.Data.IDbCommand GenerateDeleteSql <T>(T ob)
        {
            var TargetType = typeof(T);

            if (deleteCommand.ContainsKey(TargetType) == false)
            {
                String TableName  = helper.GetTable(TargetType);
                var    Properties = TargetType.GetProperties();
                MSSQLScriptSqlPatternFactory     factory = new MSSQLScriptSqlPatternFactory();
                System.Data.SqlClient.SqlCommand command = new System.Data.SqlClient.SqlCommand();
                String sql    = "DELETE  " + TableName + " Where  ";
                var    parity = factory.GetExistSql <T>(Properties, ob);
                command.Parameters.AddRange(parity.Params.ToArray());
                command.CommandText = sql + parity.SqlScript;
                deleteCommand.Add(TargetType, command);
            }
            var deletedcommand = (deleteCommand[TargetType] as SqlCommand).Clone();

            SetValues <T>(ob, deletedcommand);
            return(deletedcommand);
        }