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()); } }
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("不支持的数据库类型"); } }
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); }