private void SetManyToManyRelation(Type t, object key1, object key2)
 {
     if ((Info.CrossTables.ContainsKey(t) && (key1 != null)) && (key2 != null))
     {
         CrossTable table = Info.CrossTables[t];
         var builder = new InsertStatementBuilder(new FromClause(table.Name));
         builder.Values.Add(new KeyOpValue(table[0].Column, key1, KvOpertation.None));
         builder.Values.Add(new KeyOpValue(table[1].Column, key2, KvOpertation.None));
         SqlStatement sql = builder.ToSqlStatement(Provider.Dialect, Info.QueryRequiredFields, Info.AllowSqlLog);
         Provider.ExecuteNonQuery(sql);
     }
 }
Exemple #2
0
 public virtual object ExecuteInsert(InsertStatementBuilder sb, ObjectInfo info, DataProvider provider)
 {
     if (info.HasOnePrimaryKey && info.KeyMembers[0].MemberType == typeof(Guid))
     {
         if(info.KeyMembers[0].Is.DbGenerateGuid)
         {
             Guid key = Util.NewGuid();
             sb.Values[0].Value = key;
         }
         SqlStatement sql = sb.ToSqlStatement(provider.Dialect, null, info.AllowSqlLog);
         provider.ExecuteNonQuery(sql);
         return sb.Values[0].Value;
     }
     return ExecuteInsertIntKey(sb, info, provider);
 }
Exemple #3
0
 protected virtual object ExecuteInsertIntKey(InsertStatementBuilder sb, ObjectInfo info, DataProvider provider)
 {
     SqlStatement sql = sb.ToSqlStatement(provider.Dialect, null, info.AllowSqlLog);
     sql.SqlCommandText = AddIdentitySelectToInsert(sql.SqlCommandText);
     return provider.ExecuteScalar(sql);
 }
Exemple #4
0
 private bool WriteSingleToServer(InsertStatementBuilder sb)
 {
     SqlStatement sql = sb.ToSqlStatement(_provider.Dialect, null);
     sql.SqlTimeOut = _bulkCopyTimeout;
     _provider.ExecuteNonQuery(sql);
     _count++;
     if (_batchSize > 0 && (_count % _batchSize) == 0)
     {
         var cc = Scope<ConnectionContext>.Current;
         cc.Commit();
         cc.BeginTransaction();
     }
     if (SqlRowsCopied != null && _notifyAfter > 0 && ((_count % _notifyAfter) == 0))
     {
         var e = new SqlRowsCopiedEventArgs(_count);
         SqlRowsCopied(this, e);
         if (e.Abort) { return false; }
     }
     return true;
 }