Пример #1
0
        /// <summary>
        /// 执行sql查询
        /// </summary>
        /// <example>SqlQueryEx("select * from [Table] where name=@0 and password=@1", "abc", "123456")</example>
        /// <typeparam name="TElement">实体类型</typeparam>
        /// <param name="database">数据库对象</param>
        /// <param name="sql">sql语句</param>
        /// <param name="values">参数值</param>
        /// <returns></returns>
        public static IEnumerable <TElement> SqlQueryEx <TElement>(this Database database, string sql,
                                                                   params object[] values)
        {
            var param = QueryableExtensions.MakeSqlParameter(sql, values);

            return(database.SqlQuery <TElement>(sql, param));
        }
Пример #2
0
        //public static IQueryable<TEntity> Select<TEntity>(this IQueryable query)
        //{
        //    if (query == null)
        //    {
        //        throw new ArgumentNullException(nameof(query));
        //    }
        //    return query.ProjectTo<TEntity>();
        //}

        #region 动态执行Sql语句扩展
        /// <summary>
        /// 执行sql命令
        /// </summary>
        /// <example>ExecuteSqlCommandEx("delete from [Table] where ID=@0", Guid.Empty)</example>
        /// <param name="database">数据库对象</param>
        /// <param name="sql">sql语句</param>
        /// <param name="values">参数值</param>
        /// <returns></returns>
        public static int ExecuteSqlCommandEx(this Database database, string sql, params object[] values)
        {
            var param = QueryableExtensions.MakeSqlParameter(sql, values);

            return(database.ExecuteSqlCommand(sql, param));
        }