Ejemplo n.º 1
0
        /// <summary>
        /// 执行SQL语句并更新成员
        /// </summary>
        /// <typeparam name="valueType">数据类型</typeparam>
        /// <typeparam name="modelType">模型类型</typeparam>
        /// <param name="sqlTool">SQL操作工具</param>
        /// <param name="connection">SQL连接</param>
        /// <param name="value">目标对象</param>
        /// <param name="query">查询信息</param>
        /// <returns>更新是否成功</returns>
        internal bool Get <valueType, modelType>
            (Sql.Table <valueType, modelType> sqlTool, ref DbConnection connection, valueType value, ref GetQuery <modelType> query)
            where valueType : class, modelType
            where modelType : class
        {
            if (connection == null)
            {
                connection = GetConnection();
            }
            if (connection != null)
            {
                bool isFinally = false;
                try
                {
                    using (DbCommand command = getCommand(connection, query.Sql))
                        using (DbDataReader reader = command.ExecuteReader(CommandBehavior.SingleResult))
                        {
                            if (reader.Read())
                            {
                                DataModel.Model <modelType> .Setter.Set(reader, value, query.MemberMap);

                                return(isFinally = true);
                            }
                        }
                    isFinally = true;
                }
                finally
                {
                    if (!isFinally)
                    {
                        sqlTool.Log.Add(AutoCSer.Log.LogType.Error, query.Sql);
                    }
                }
            }
            return(false);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// 查询对象
 /// </summary>
 /// <typeparam name="valueType">对象类型</typeparam>
 /// <typeparam name="modelType">模型类型</typeparam>
 /// <param name="sqlTool">SQL操作工具</param>
 /// <param name="value">匹配成员值</param>
 /// <param name="memberMap">成员位图</param>
 /// <param name="query">查询信息</param>
 internal abstract void GetByPrimaryKey <valueType, modelType>
     (Sql.Table <valueType, modelType> sqlTool, valueType value, MemberMap <modelType> memberMap, ref GetQuery <modelType> query)
     where valueType : class, modelType
     where modelType : class;