protected virtual DbCommand GeneratePlainInsertCommand(CommandBuilder commandBuilder, object entity) { var cmd = commandBuilder.DataService.DbProviderFactory.CreateCommand(); StringBuilder commandText = new StringBuilder(); commandBuilder.AppendInsertStatement(entity, cmd, commandText); cmd.CommandText = commandText.ToString(); return cmd; }
protected virtual DbCommand GenerateInsertCommandWithAutogeneratedField(CommandBuilder commandBuilder, object entity, EntityMetadata entityMetadata) { var cmd = commandBuilder.DataService.DbProviderFactory.CreateCommand(); StringBuilder commandText = new StringBuilder(); commandBuilder.AppendInsertStatement(entity, cmd, commandText); AppendGetAutoincrementField(commandText, entityMetadata); cmd.CommandText = commandText.ToString(); return cmd; }
public virtual DbCommand GenerateInsertCommand(CommandBuilder commandBuilder, object entity) { var entityType = entity.GetType(); var entityMetadata = entityType.GetEntityMetadata(); if (entityMetadata.AutogeneratedFieldName == null) { return GeneratePlainInsertCommand(commandBuilder, entity); } else { return GenerateInsertCommandWithAutogeneratedField(commandBuilder, entity, entityMetadata); } }
private void Initialize() { this.EntityNameToEntityViewTransform = TextTransform.None; this.commandBuilder = new CommandBuilder(this); this.SpecialFieldNames = new SpecialFieldNames(); this.MaxRetries = 2; this.InitialMillisecondsRetryDelay = 20; this.IsAutomaticAuditDateFieldsEnabled = true; this.IsAutomaticAuditUserFieldsEnabled = true; this.CommandTimeout = -1; }
protected override DbCommand GenerateInsertCommandWithAutogeneratedField(CommandBuilder commandBuilder, object entity, EntityMetadata entityMetadata) { if (!string.IsNullOrEmpty(entityMetadata.AutoIncrementFieldName)) return base.GenerateInsertCommandWithAutogeneratedField(commandBuilder, entity, entityMetadata); if (string.IsNullOrEmpty(entityMetadata.SequenceFieldName)) throw new InvalidOperationException(entity.GetType().Name + " has no autogenerated field"); var cmd = commandBuilder.DataService.DbProviderFactory.CreateCommand(); StringBuilder commandText = new StringBuilder(); commandText.Append(string.Format("DECLARE {0} bigint = NEXT VALUE FOR {1};", SequenceVariable, entityMetadata.GetFullSequenceName(this.DefaultSchema))); commandBuilder.AppendInsertStatement(entity, cmd, commandText); commandText.Append(string.Format(";\nSELECT {0} AS AutogeneratedField;", SequenceVariable)); cmd.CommandText = commandText.ToString(); return cmd; }
protected override DbCommand GenerateInsertCommandWithAutogeneratedField(CommandBuilder commandBuilder, object entity, EntityMetadata entityMetadata) { var cmd = commandBuilder.DataService.DbProviderFactory.CreateCommand(); StringBuilder commandText = new StringBuilder(); commandText.Append(string.Format(@" DECLARE {0} NUMERIC(18); BEGIN {0} := {1}.nextval;", SequenceVariable, entityMetadata.GetFullSequenceName(commandBuilder.DataService.EntityLiteProvider.DefaultSchema))); commandBuilder.AppendInsertStatement(entity, cmd, commandText); commandText.Append(string.Format(@"; :id_seq_$param$ := {0}; END;", SequenceVariable)); IDbDataParameter idp = cmd.CreateParameter(); idp.ParameterName = ":id_seq_$param$"; idp.Direction = ParameterDirection.Output; idp.DbType = DbType.Int64; cmd.Parameters.Add(idp); cmd.CommandText = commandText.ToString(); return cmd; }