Skip to content

Commit d8de581

Browse files
committed
Fixed returning clause (DNET-850).
1 parent e292153 commit d8de581

File tree

3 files changed

+95
-1
lines changed

3 files changed

+95
-1
lines changed

Provider/src/FirebirdSql.EntityFrameworkCore.Firebird.Tests/EndToEnd/InsertTests.cs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,5 +173,50 @@ public void DefaultValuesInsert()
173173
Assert.AreEqual("27foobar", entity.Name);
174174
}
175175
}
176+
177+
class TwoComputedInsertContext : FbTestDbContext
178+
{
179+
public TwoComputedInsertContext(string connectionString)
180+
: base(connectionString)
181+
{ }
182+
183+
protected override void OnModelCreating(ModelBuilder modelBuilder)
184+
{
185+
base.OnModelCreating(modelBuilder);
186+
187+
var insertEntityConf = modelBuilder.Entity<TwoComputedInsertEntity>();
188+
insertEntityConf.Property(x => x.Id).HasColumnName("ID")
189+
.UseFirebirdIdentityColumn();
190+
insertEntityConf.Property(x => x.Name).HasColumnName("NAME");
191+
insertEntityConf.Property(x => x.Computed1).HasColumnName("COMPUTED1")
192+
.ValueGeneratedOnAddOrUpdate();
193+
insertEntityConf.Property(x => x.Computed2).HasColumnName("COMPUTED2")
194+
.ValueGeneratedOnAddOrUpdate();
195+
insertEntityConf.ToTable("TEST_INSERT_2COMPUTED");
196+
}
197+
}
198+
class TwoComputedInsertEntity
199+
{
200+
public int Id { get; set; }
201+
public string Name { get; set; }
202+
public string Computed1 { get; set; }
203+
public string Computed2 { get; set; }
204+
}
205+
[Test]
206+
public void TwoComputedInsert()
207+
{
208+
if (!EnsureVersion(new Version("3.0.0.0")))
209+
return;
210+
211+
using (var db = GetDbContext<TwoComputedInsertContext>())
212+
{
213+
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))");
214+
var entity = new TwoComputedInsertEntity() { Name = "foobar" };
215+
db.Add(entity);
216+
db.SaveChanges();
217+
Assert.AreEqual("1foobar", entity.Computed1);
218+
Assert.AreEqual("2foobar", entity.Computed2);
219+
}
220+
}
176221
}
177222
}

Provider/src/FirebirdSql.EntityFrameworkCore.Firebird.Tests/EndToEnd/UpdateTests.cs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,5 +185,50 @@ public void ConcurrencyUpdateNoGenerated()
185185
Assert.Throws<DbUpdateConcurrencyException>(() => db.SaveChanges());
186186
}
187187
}
188+
189+
class TwoComputedUpdateContext : FbTestDbContext
190+
{
191+
public TwoComputedUpdateContext(string connectionString)
192+
: base(connectionString)
193+
{ }
194+
195+
protected override void OnModelCreating(ModelBuilder modelBuilder)
196+
{
197+
base.OnModelCreating(modelBuilder);
198+
199+
var insertEntityConf = modelBuilder.Entity<TwoComputedUpdateEntity>();
200+
insertEntityConf.Property(x => x.Id).HasColumnName("ID");
201+
insertEntityConf.Property(x => x.Foo).HasColumnName("FOO");
202+
insertEntityConf.Property(x => x.Bar).HasColumnName("BAR");
203+
insertEntityConf.Property(x => x.Computed1).HasColumnName("COMPUTED1")
204+
.ValueGeneratedOnAddOrUpdate();
205+
insertEntityConf.Property(x => x.Computed2).HasColumnName("COMPUTED2")
206+
.ValueGeneratedOnAddOrUpdate();
207+
insertEntityConf.ToTable("TEST_UPDATE_2COMPUTED");
208+
}
209+
}
210+
class TwoComputedUpdateEntity
211+
{
212+
public int Id { get; set; }
213+
public string Foo { get; set; }
214+
public string Bar { get; set; }
215+
public string Computed1 { get; set; }
216+
public string Computed2 { get; set; }
217+
}
218+
[Test]
219+
public void TwoComputedUpdate()
220+
{
221+
using (var db = GetDbContext<TwoComputedUpdateContext>())
222+
{
223+
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))");
224+
db.Database.ExecuteSqlCommand("update or insert into test_update_2computed values (66, 'foo', 'bar')");
225+
var entity = new TwoComputedUpdateEntity() { Id = 66, Foo = "test", Bar = "test" };
226+
var entry = db.Attach(entity);
227+
entry.Property(x => x.Foo).IsModified = true;
228+
db.SaveChanges();
229+
Assert.AreEqual("testbar", entity.Computed1);
230+
Assert.AreEqual("barbar", entity.Computed2);
231+
}
232+
}
188233
}
189234
}

Provider/src/FirebirdSql.EntityFrameworkCore.Firebird/Update/Internal/FbUpdateSqlGenerator.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,11 @@ public override ResultSetMapping AppendUpdateOperation(StringBuilder commandStri
125125
commandStringBuilder.AppendJoin(readOperations, (b, e) =>
126126
{
127127
b.Append(SqlGenerationHelper.DelimitIdentifier(e.ColumnName));
128-
b.Append(" INTO :");
128+
}, ", ");
129+
commandStringBuilder.Append(" INTO ");
130+
commandStringBuilder.AppendJoin(readOperations, (b, e) =>
131+
{
132+
b.Append(":");
129133
b.Append(SqlGenerationHelper.DelimitIdentifier(e.ColumnName));
130134
}, ", ");
131135
}

0 commit comments

Comments
 (0)