Beispiel #1
0
        /// <summary>
        /// 自定义更新扩展
        /// </summary>
        /// <typeparam name="TEntity"></typeparam>
        /// <param name="context"></param>
        /// <param name="entity">更新实体</param>
        /// <param name="predicate">更新条件</param>
        /// <returns></returns>
        public static bool MangoUpdate <TEntity>(this DbContext context, TEntity entity, Expression <Func <TEntity, bool> > predicate) where TEntity : class, new()
        {
            TSqlAssembledResult result = TSqlAssembled.Update <TEntity>(entity, predicate);

            context.Database.ExecuteSqlRaw(result.SqlStr, result.SqlParameters);
            return(context.SaveChanges() > 0 ? true : false);
        }
Beispiel #2
0
        /// <summary>
        /// 自定义更新扩展
        /// </summary>
        /// <typeparam name="TEntity"></typeparam>
        /// <param name="context"></param>
        /// <param name="fields">更新字段</param>
        /// <param name="predicate">更新条件</param>
        /// <returns></returns>
        public static int MangoUpdate <TEntity>(this DbContext context, Expression <Func <TEntity, bool> > fields, Expression <Func <TEntity, bool> > predicate) where TEntity : class, new()
        {
            TSqlAssembledResult result = TSqlAssembled.Update <TEntity>(fields, predicate);

            return(context.Database.ExecuteSqlRaw(result.SqlStr));
        }