- Notifications
You must be signed in to change notification settings - Fork 57
Run SQL Server script
Jon P Smith edited this page Nov 9, 2021
·
2 revisions
The ExecuteScriptFileInTransaction extension method will do what method name says.
The format of the file is important - each SQL command must end with GO at the start of the line after the command.
Here is an example using this method
[Fact]publicvoidTestApplyScriptOneCommandToDatabaseOk(){//SETUPvaroptions=this.CreateUniqueClassOptions<EfCoreContext>();varfilepath=TestData.GetFilePath("Script01 - Add row to Authors table.sql");using(varcontext=newEfCoreContext(options)){context.CreateEmptyViaWipe();//ATTEMPTcontext.ExecuteScriptFileInTransaction(filepath);//VERIFYcontext.Authors.Count().ShouldEqual(2);}}Here is a simple example of what the SQL script should look like, with GO on a newline after each SQL command
INSERT INTO Authors (Name) VALUES('Row 1')
GO
INSERT INTO Authors (Name) VALUES('Row 2')
GO- Testing against a PostgreSQL db
- Changes in EfCore.TestSupport 5
- Testing with production data
- Using an in-memory database (old)