-
-
Notifications
You must be signed in to change notification settings - Fork 73
Added AppendStoredProcedureCall #1185
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Camel-RD
wants to merge
6
commits into
FirebirdSQL:master
Choose a base branch
from
Camel-RD:NETProvider-b1
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+989
−0
Open
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
6e702cb
added AppendStoredProcedureCall
Camel-RD 7a80ede
call sp as selectable; tests
Camel-RD b8e4a3f
fixes
Camel-RD 53fccb6
added NUMERIC type to typa mapping source
Camel-RD c921270
Revert "added NUMERIC type to typa mapping source"
Camel-RD 1b5afa3
updated AppendStoredProcedureCall and tests
Camel-RD File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
150 changes: 150 additions & 0 deletions
150
src/FirebirdSql.EntityFrameworkCore.Firebird.Tests/EndToEndUsingSP/DeleteTestsUsingSP.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
/* | ||
* The contents of this file are subject to the Initial | ||
* Developer's Public License Version 1.0 (the "License"); | ||
* you may not use this file except in compliance with the | ||
* License. You may obtain a copy of the License at | ||
* https://github.com/FirebirdSQL/NETProvider/raw/master/license.txt. | ||
* | ||
* Software distributed under the License is distributed on | ||
* an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either | ||
* express or implied. See the License for the specific | ||
* language governing rights and limitations under the License. | ||
* | ||
* All Rights Reserved. | ||
*/ | ||
|
||
//$Authors = Jiri Cincura ([email protected]) | ||
|
||
using System; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Microsoft.EntityFrameworkCore; | ||
using NUnit.Framework; | ||
|
||
namespace FirebirdSql.EntityFrameworkCore.Firebird.Tests.EndToEnd; | ||
|
||
public class DeleteTestsUsingSP : EntityFrameworkCoreTestsBase | ||
{ | ||
class DeleteContext : FbTestDbContext | ||
{ | ||
public DeleteContext(string connectionString) | ||
: base(connectionString) | ||
{ } | ||
|
||
protected override void OnTestModelCreating(ModelBuilder modelBuilder) | ||
{ | ||
base.OnTestModelCreating(modelBuilder); | ||
|
||
var insertEntityConf = modelBuilder.Entity<DeleteEntity>(); | ||
insertEntityConf.Property(x => x.Id).HasColumnName("ID"); | ||
insertEntityConf.Property(x => x.Name).HasColumnName("NAME"); | ||
insertEntityConf.ToTable("TEST_DELETE_USP"); | ||
modelBuilder.Entity<DeleteEntity>().DeleteUsingStoredProcedure("SP_TEST_DELETE", | ||
storedProcedureBuilder => | ||
{ | ||
storedProcedureBuilder.HasOriginalValueParameter(x => x.Id); | ||
storedProcedureBuilder.HasRowsAffectedResultColumn(); | ||
}); | ||
} | ||
} | ||
class DeleteEntity | ||
{ | ||
public int Id { get; set; } | ||
public string Name { get; set; } | ||
} | ||
[Test] | ||
public async Task Delete() | ||
{ | ||
await using (var db = await GetDbContext<DeleteContext>()) | ||
{ | ||
await db.Database.ExecuteSqlRawAsync("create table test_delete_usp (id int primary key, name varchar(20))"); | ||
await db.Database.ExecuteSqlRawAsync("insert into test_delete_usp values (65, 'test')"); | ||
await db.Database.ExecuteSqlRawAsync("insert into test_delete_usp values (66, 'test')"); | ||
await db.Database.ExecuteSqlRawAsync("insert into test_delete_usp values (67, 'test')"); | ||
var sp = """ | ||
create or alter procedure sp_test_delete ( | ||
pid integer) | ||
returns (rowcount integer) | ||
as | ||
begin | ||
delete from test_delete_usp where id = :pid; | ||
rowcount = row_count; | ||
suspend; | ||
end | ||
"""; | ||
await db.Database.ExecuteSqlRawAsync(sp); | ||
var entity = new DeleteEntity() { Id = 66 }; | ||
var entry = db.Attach(entity); | ||
entry.State = EntityState.Deleted; | ||
await db.SaveChangesAsync(); | ||
var values = await db.Set<DeleteEntity>() | ||
.FromSqlRaw("select * from test_delete_usp") | ||
.AsNoTracking() | ||
.OrderBy(x => x.Id) | ||
.ToListAsync(); | ||
Assert.AreEqual(2, values.Count()); | ||
Assert.AreEqual(65, values[0].Id); | ||
Assert.AreEqual(67, values[1].Id); | ||
} | ||
} | ||
|
||
class ConcurrencyDeleteContext : FbTestDbContext | ||
{ | ||
public ConcurrencyDeleteContext(string connectionString) | ||
: base(connectionString) | ||
{ } | ||
|
||
protected override void OnTestModelCreating(ModelBuilder modelBuilder) | ||
{ | ||
base.OnTestModelCreating(modelBuilder); | ||
|
||
var insertEntityConf = modelBuilder.Entity<ConcurrencyDeleteEntity>(); | ||
insertEntityConf.Property(x => x.Id).HasColumnName("ID"); | ||
insertEntityConf.Property(x => x.Name).HasColumnName("NAME"); | ||
insertEntityConf.Property(x => x.Stamp).HasColumnName("STAMP") | ||
.IsRowVersion(); | ||
insertEntityConf.ToTable("TEST_DELETE_CONCURRENCY_USP"); | ||
modelBuilder.Entity<ConcurrencyDeleteEntity>().DeleteUsingStoredProcedure("SP_TEST_DELETE_CONCURRENCY", | ||
storedProcedureBuilder => | ||
{ | ||
storedProcedureBuilder.HasOriginalValueParameter(x => x.Id); | ||
storedProcedureBuilder.HasOriginalValueParameter(x => x.Stamp); | ||
storedProcedureBuilder.HasRowsAffectedResultColumn(); | ||
}); | ||
cincuranet marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
class ConcurrencyDeleteEntity | ||
{ | ||
public int Id { get; set; } | ||
public string Name { get; set; } | ||
public DateTime Stamp { get; set; } | ||
} | ||
[Test] | ||
public async Task ConcurrencyDelete() | ||
{ | ||
await using (var db = await GetDbContext<ConcurrencyDeleteContext>()) | ||
{ | ||
await db.Database.ExecuteSqlRawAsync("create table test_delete_concurrency_usp (id int primary key, name varchar(20), stamp timestamp)"); | ||
await db.Database.ExecuteSqlRawAsync("insert into test_delete_concurrency_usp values (65, 'test', current_timestamp)"); | ||
await db.Database.ExecuteSqlRawAsync("insert into test_delete_concurrency_usp values (66, 'test', current_timestamp)"); | ||
await db.Database.ExecuteSqlRawAsync("insert into test_delete_concurrency_usp values (67, 'test', current_timestamp)"); | ||
var sp = """ | ||
create or alter procedure sp_test_delete_concurrency ( | ||
pid integer, | ||
pstamp timestamp) | ||
returns (rowcount integer) | ||
as | ||
begin | ||
delete from test_delete_concurrency_usp where id = :pid and stamp = :pstamp; | ||
rowcount = row_count; | ||
if (rowcount > 0) then suspend; | ||
cincuranet marked this conversation as resolved.
Show resolved
Hide resolved
|
||
end | ||
"""; | ||
await db.Database.ExecuteSqlRawAsync(sp); | ||
var entity = new ConcurrencyDeleteEntity() { Id = 66, Stamp = new DateTime(1970, 1, 1) }; | ||
var entry = db.Attach(entity); | ||
entry.State = EntityState.Deleted; | ||
Assert.ThrowsAsync<DbUpdateConcurrencyException>(() => db.SaveChangesAsync()); | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.