예제 #1
0
        /// <summary>
        /// 支持from语法的join写法
        /// </summary>
        /// <typeparam name="TOuter"></typeparam>
        /// <typeparam name="TInner"></typeparam>
        /// <typeparam name="TKey"></typeparam>
        /// <typeparam name="TResult"></typeparam>
        /// <param name="outer"></param>
        /// <param name="inner"></param>
        /// <param name="outerKeySelector"></param>
        /// <param name="innerKeySelector"></param>
        /// <param name="resultSelector"></param>
        /// <returns></returns>
        public static DMS <TResult> Join <TOuter, TInner, TKey, TResult>(this DMS <TOuter> outer,
                                                                         DMS <TInner> inner, Expression <Func <TOuter, TKey> > outerKeySelector,
                                                                         Expression <Func <TInner, TKey> > innerKeySelector, Expression <Func <TOuter, TInner, TResult> > resultSelector)
            where TInner : class
            where TOuter : class
            where TResult : class
        {
            ParameterExpression xExpr = Expression.Parameter(typeof(TOuter), "x");
            ParameterExpression yExpr = Expression.Parameter(typeof(TInner), "y");

            if (typeof(TKey).IsPrimitive())
            {
                Expression bExpr     = Expression.MakeBinary(ExpressionType.Equal, outerKeySelector.Body, innerKeySelector.Body);
                var        whereClip = Expression.Lambda <Func <TOuter, TInner, bool> >(bExpr, xExpr, yExpr);
                var        innerJoin = DMS.Create <TInner>();
                var        list      = Join(outer, innerJoin, whereClip, resultSelector);
                return(list);
            }
            else
            {
                NewExpression OutterNewExpr = outerKeySelector.Body as NewExpression;
                NewExpression InnerNewExpr  = innerKeySelector.Body as NewExpression;
                int           index         = 0;
                Expression    binaryExpr    = null;
                //进行分解得到表达式
                foreach (Expression item in OutterNewExpr.Arguments)
                {
                    var rightExpr = Expression.MakeBinary(ExpressionType.Equal, item, InnerNewExpr.Arguments[index++]);
                    if (binaryExpr == null)
                    {
                        binaryExpr = rightExpr;
                    }
                    else
                    {
                        binaryExpr = Expression.MakeBinary(ExpressionType.AndAlso, binaryExpr, rightExpr);
                    }
                }
                var whereClip = Expression.Lambda <Func <TOuter, TInner, bool> >(binaryExpr, xExpr, yExpr);
                var innerJoin = DMS.Create <TInner>();
                var list      = Join(outer, innerJoin, whereClip, resultSelector);
                return(list);
            }
        }
예제 #2
0
        /// <summary>
        /// 新增一项数据
        /// </summary>
        /// <param name="entity">添加的实体参数</param>
        /// <param name="result">是否需要返回结果才继续执行,默认为true</param>
        /// <param name="bDataBase">数据库名称(默认为当前数据库)</param>
        /// <param name="tableFunc">替换表名称</param>
        public void AddTS <T>(T entity, bool result, string bDataBase = ConstExpression.DataBase, Expression <Func <Type, string> > tableFunc = null) where T : class, IEntity
        {
            DMS dms = DMS.Create(entity, entity.GetType(), bDataBase).DMSInsert(entity);

            if (tableFunc != null)
            {
                dms.TableExpressioin.ReplaceTable(tableFunc);
            }
            string resultSql = dms.GetResultSql();
            TransactionScopeEntity tEntity = new TransactionScopeEntity()
            {
                DataParameter = dms.dynamicParameters,
                ResultSql     = resultSql,
                ElementType   = entity.GetType(),
                ResultFlag    = result,
                ExcuteType    = DMSExcuteType.INSERT,
            };

            changeInternalDbProvider(entity.GetType());
            TransactionScopeEntityList.Enqueue(tEntity);
        }
예제 #3
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="whereFunc"></param>
 /// <returns></returns>
 public int DeleteAsync(Expression <Func <T, bool> > whereFunc)
 {
     return(DMS.Create <T>().Delete(whereFunc));
 }
예제 #4
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="whereFunc"></param>
 /// <returns></returns>
 public T Get(Expression <Func <T, bool> > whereFunc)
 {
     return(DMS.Create <T>().Where(whereFunc).ToEntity());
 }
예제 #5
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="entity"></param>
 /// <returns></returns>
 public int AddIdentityAsync(T entity)
 {
     return(DMS.Create <T>().InsertIdentity(entity));
 }
예제 #6
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="entity"></param>
 /// <param name="whereFunc"></param>
 /// <returns></returns>
 public int UpdateAsync(T entity, Expression <Func <T, bool> > whereFunc)
 {
     return(DMS.Create <T>().Edit(entity, whereFunc));
 }
예제 #7
0
 /// <summary>
 ///
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="entity"></param>
 /// <param name="whereFunc"></param>
 /// <returns></returns>
 public static T Get <T>(this T entity, System.Linq.Expressions.Expression <Func <T, bool> > whereFunc)
     where T : class, IEntity
 {
     return(DMS.Create <T>().Where(whereFunc).ToEntity());
 }
예제 #8
0
 /// <summary>
 ///
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="entity"></param>
 /// <returns></returns>
 public static int AddIdentityAsync <T>(this T entity)
     where T : class, IEntity
 {
     return(DMS.Create <T>().InsertIdentity(entity));
 }
예제 #9
0
 /// <summary>
 ///
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="entity"></param>
 /// <param name="whereFunc"></param>
 /// <returns></returns>
 public static int UpdateAsync <T>(this T entity, System.Linq.Expressions.Expression <Func <T, bool> > whereFunc)
     where T : class, IEntity
 {
     return(DMS.Create <T>().Edit(entity, whereFunc));
 }