Skip to content

Commit

Permalink
Fixed returning clause (DNET-850).
Browse files Browse the repository at this point in the history
  • Loading branch information
cincuranet committed Sep 10, 2018
1 parent e292153 commit d8de581
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 1 deletion.
Expand Up @@ -173,5 +173,50 @@ public void DefaultValuesInsert()
Assert.AreEqual("27foobar", entity.Name);
}
}

class TwoComputedInsertContext : FbTestDbContext
{
public TwoComputedInsertContext(string connectionString)
: base(connectionString)
{ }

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);

var insertEntityConf = modelBuilder.Entity<TwoComputedInsertEntity>();
insertEntityConf.Property(x => x.Id).HasColumnName("ID")
.UseFirebirdIdentityColumn();
insertEntityConf.Property(x => x.Name).HasColumnName("NAME");
insertEntityConf.Property(x => x.Computed1).HasColumnName("COMPUTED1")
.ValueGeneratedOnAddOrUpdate();
insertEntityConf.Property(x => x.Computed2).HasColumnName("COMPUTED2")
.ValueGeneratedOnAddOrUpdate();
insertEntityConf.ToTable("TEST_INSERT_2COMPUTED");
}
}
class TwoComputedInsertEntity
{
public int Id { get; set; }
public string Name { get; set; }
public string Computed1 { get; set; }
public string Computed2 { get; set; }
}
[Test]
public void TwoComputedInsert()
{
if (!EnsureVersion(new Version("3.0.0.0")))
return;

using (var db = GetDbContext<TwoComputedInsertContext>())
{
db.Database.ExecuteSqlCommand("create table test_insert_2computed (id int generated by default as identity (start with 26) primary key, name varchar(20), computed1 generated always as ('1' || name), computed2 generated always as ('2' || name))");
var entity = new TwoComputedInsertEntity() { Name = "foobar" };
db.Add(entity);
db.SaveChanges();
Assert.AreEqual("1foobar", entity.Computed1);
Assert.AreEqual("2foobar", entity.Computed2);
}
}
}
}
Expand Up @@ -185,5 +185,50 @@ public void ConcurrencyUpdateNoGenerated()
Assert.Throws<DbUpdateConcurrencyException>(() => db.SaveChanges());
}
}

class TwoComputedUpdateContext : FbTestDbContext
{
public TwoComputedUpdateContext(string connectionString)
: base(connectionString)
{ }

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);

var insertEntityConf = modelBuilder.Entity<TwoComputedUpdateEntity>();
insertEntityConf.Property(x => x.Id).HasColumnName("ID");
insertEntityConf.Property(x => x.Foo).HasColumnName("FOO");
insertEntityConf.Property(x => x.Bar).HasColumnName("BAR");
insertEntityConf.Property(x => x.Computed1).HasColumnName("COMPUTED1")
.ValueGeneratedOnAddOrUpdate();
insertEntityConf.Property(x => x.Computed2).HasColumnName("COMPUTED2")
.ValueGeneratedOnAddOrUpdate();
insertEntityConf.ToTable("TEST_UPDATE_2COMPUTED");
}
}
class TwoComputedUpdateEntity
{
public int Id { get; set; }
public string Foo { get; set; }
public string Bar { get; set; }
public string Computed1 { get; set; }
public string Computed2 { get; set; }
}
[Test]
public void TwoComputedUpdate()
{
using (var db = GetDbContext<TwoComputedUpdateContext>())
{
db.Database.ExecuteSqlCommand("create table test_update_2computed (id int primary key, foo varchar(20), bar varchar(20), computed1 generated always as (foo || bar), computed2 generated always as (bar || bar))");
db.Database.ExecuteSqlCommand("update or insert into test_update_2computed values (66, 'foo', 'bar')");
var entity = new TwoComputedUpdateEntity() { Id = 66, Foo = "test", Bar = "test" };
var entry = db.Attach(entity);
entry.Property(x => x.Foo).IsModified = true;
db.SaveChanges();
Assert.AreEqual("testbar", entity.Computed1);
Assert.AreEqual("barbar", entity.Computed2);
}
}
}
}
Expand Up @@ -125,7 +125,11 @@ public override ResultSetMapping AppendUpdateOperation(StringBuilder commandStri
commandStringBuilder.AppendJoin(readOperations, (b, e) =>
{
b.Append(SqlGenerationHelper.DelimitIdentifier(e.ColumnName));
b.Append(" INTO :");
}, ", ");
commandStringBuilder.Append(" INTO ");
commandStringBuilder.AppendJoin(readOperations, (b, e) =>
{
b.Append(":");
b.Append(SqlGenerationHelper.DelimitIdentifier(e.ColumnName));
}, ", ");
}
Expand Down

0 comments on commit d8de581

Please sign in to comment.