Пример #1
0
 public override int Excute()
 {
     using (var translator = DMObjectContainer.GetTSQLTranslator())
     {
         TranResult   tr  = translator.CreateDeleteTSQL <T1>(where.LambdaExpression);
         ATSqlCommand cmd = new ATSqlCommand();
         cmd.SetCmdText(tr.CmdText);
         cmd.SetParameters(tr.Parameter.ToArray());
         cmd.SetTrans(base.trans);
         cmd.SetConnectionString(base.ConnectionString);
         return(cmd.ExecuteNonQuery());
     }
 }
Пример #2
0
 public virtual List <TResult> ToList(int top)
 {
     using (var translator = DMObjectContainer.GetTSQLTranslator())
     {
         using (TranResult tr = translator.CreateSelectListTSQL <T1>(top, where.LambdaExpression, order.LambdaExpression, select.LambdaExpression, group.LambdaExpression, join.LambdaExpression))
         {
             using (ATSqlCommand cmd = new ATSqlCommand())
             {
                 cmd.SetCmdText(tr.CmdText);
                 cmd.SetParameters(tr.Parameter.ToArray());
                 cmd.SetConnectionString(base.ConnectionString);
                 return(cmd.ToList <TResult>());
             }
         }
     }
 }
Пример #3
0
 public virtual TResult Single()
 {
     using (var translator = DMObjectContainer.GetTSQLTranslator())
     {
         using (TranResult tr = translator.CreateSelectTSQL <T1>(where.LambdaExpression, select.LambdaExpression, join.LambdaExpression))
         {
             using (ATSqlCommand cmd = new ATSqlCommand())
             {
                 cmd.SetCmdText(tr.CmdText);
                 cmd.SetParameters(tr.Parameter.ToArray());
                 cmd.SetConnectionString(base.ConnectionString);
                 return(cmd.ToEntity <TResult>());
             }
         }
     }
 }
Пример #4
0
 public TResult Excute()
 {
     using (var translator = DMObjectContainer.GetTSQLTranslator())
     {
         using (TranResult tr = translator.CreateAggregateTSQL <T1>(where.LambdaExpression, select.LambdaExpression, group.LambdaExpression, join.LambdaExpression))
         {
             using (ATSqlCommand cmd = new ATSqlCommand())
             {
                 cmd.SetCmdText(tr.CmdText);
                 cmd.SetParameters(tr.Parameter.ToArray());
                 cmd.SetConnectionString(base.ConnectionString);
                 return(cmd.ExecuteScalar <TResult>());
             }
         }
     }
 }
Пример #5
0
        public virtual PageList <TResult> ToPageList(int pageIndex, int pageSize)
        {
            PageList <TResult> pl = new PageList <TResult>();

            using (var translator = DMObjectContainer.GetTSQLTranslator())
            {
                Expression <Func <T1, int> > count = (p) => p.DMCount("1");
                using (TranResult countTr = translator.CreateAggregateTSQL <T1>(where.LambdaExpression, count, group.LambdaExpression, join.LambdaExpression))
                {
                    using (ATSqlCommand countCmd = new ATSqlCommand())
                    {
                        countCmd.SetCmdText(countTr.CmdText);
                        countCmd.SetParameters(countTr.Parameter.ToArray());
                        countCmd.SetConnectionString(base.ConnectionString);
                        if (group.LambdaExpression != null)
                        {
                            pl.Total = countCmd.ToDataTable().Rows.Count;
                        }
                        else
                        {
                            pl.Total = countCmd.ExecuteScalar <int>();
                        }
                        pl.Index = pageIndex;
                        pl.Size  = pageSize;
                    }
                }

                if (pl.Total != 0)
                {
                    using (TranResult tr = translator.CreateSelectPageListTSQL <T1>(pageIndex, pageSize, where.LambdaExpression, order.LambdaExpression, select.LambdaExpression, group.LambdaExpression, join.LambdaExpression))
                    {
                        using (ATSqlCommand cmd = new ATSqlCommand())
                        {
                            cmd.SetCmdText(tr.CmdText);
                            cmd.SetParameters(tr.Parameter.ToArray());
                            cmd.SetConnectionString(base.ConnectionString);
                            pl.List = cmd.ToList <TResult>();
                        }
                    }
                }
                return(pl);
            }
        }
Пример #6
0
        public override int Excute()
        {
            switch (DMConfiguration.ProviderType)
            {
            case EnumProviderType.MySql:
            case EnumProviderType.MsSql:
                using (var translator = DMObjectContainer.GetTSQLTranslator())
                {
                    int        id   = 0;
                    Type       type = typeof(T1);
                    var        tm   = type.GetTableMapping();
                    var        pk   = type.GetProperty(tm.PrimaryKey.Name);
                    TranResult tr   = translator.CreateInsertTSQL <T1>(this.t, select.LambdaExpression);
                    if (pk != null && tm.PrimaryKey.IsPrimaryKey && tm.PrimaryKey.IsIdentity)
                    {
                        tr.CmdText += translator.GetIdentitySQL();
                    }
                    ATSqlCommand cmd = new ATSqlCommand();
                    cmd.SetCmdText(tr.CmdText);
                    cmd.SetParameters(tr.Parameter.ToArray());
                    cmd.SetTrans(base.trans);
                    cmd.SetConnectionString(base.ConnectionString);
                    id = cmd.ExecuteScalar();
                    if (pk != null && tm.PrimaryKey.IsPrimaryKey && tm.PrimaryKey.IsIdentity)
                    {
                        pk.SetValue(t, id, null);
                    }
                    return(id);
                }

            case EnumProviderType.Access:
                return(this.AccessExcute());

            default:
                throw new NotSupportedException("不支持的数据库类型");
            }
        }
Пример #7
0
        private int AccessExcute()
        {
            int  id   = 0;
            Type type = typeof(T1);
            var  tm   = type.GetTableMapping();
            var  pk   = type.GetProperty(tm.PrimaryKey.Name);

            using (var translator = DMObjectContainer.GetTSQLTranslator())
            {
                if (base.trans == null)
                {
                    using (var dmTrans = new DMTransaction(this.ConnectionString))
                    {
                        try
                        {
                            //这里使用事务主要是为了锁表 目的是为了获取自增ID
                            TranResult   tr  = translator.CreateInsertTSQL <T1>(this.t, select.LambdaExpression);
                            ATSqlCommand cmd = new ATSqlCommand();
                            cmd.SetCmdText(tr.CmdText);
                            cmd.SetParameters(tr.Parameter.ToArray());
                            cmd.SetTrans(dmTrans.BeginTransaction());
                            cmd.ExecuteScalar();
                            if (pk != null && tm.PrimaryKey.IsPrimaryKey && tm.PrimaryKey.IsIdentity)
                            {
                                var          identitySQL = translator.GetIdentitySQL(tm.Name);
                                ATSqlCommand accessCmd   = new ATSqlCommand();
                                accessCmd.SetCmdText(identitySQL);
                                accessCmd.SetTrans(dmTrans.BeginTransaction());
                                id = accessCmd.ExecuteScalar();
                                pk.SetValue(t, id, null);
                            }
                            dmTrans.Commit();
                        }
                        catch
                        {
                            dmTrans.Rollback();
                            throw;
                        }
                    }
                }
                else
                {
                    TranResult   tr  = translator.CreateInsertTSQL <T1>(this.t, select.LambdaExpression);
                    ATSqlCommand cmd = new ATSqlCommand();
                    cmd.SetCmdText(tr.CmdText);
                    cmd.SetParameters(tr.Parameter.ToArray());
                    cmd.SetTrans(base.trans);
                    cmd.ExecuteScalar();
                    if (pk != null && tm.PrimaryKey.IsPrimaryKey && tm.PrimaryKey.IsIdentity)
                    {
                        var          identitySQL = translator.GetIdentitySQL(tm.Name);
                        ATSqlCommand accessCmd   = new ATSqlCommand();
                        accessCmd.SetCmdText(identitySQL);
                        accessCmd.SetTrans(base.trans);
                        id = accessCmd.ExecuteScalar();
                        pk.SetValue(t, id, null);
                    }
                }
            }
            return(id);
        }