Exemplo n.º 1
0
 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 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;
        }
Exemplo n.º 3
0
 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;
 }
 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;
 }