From 7a4f342a6ce63a78232ccb16c7c94e21644de456 Mon Sep 17 00:00:00 2001 From: "Jean.R" Date: Wed, 30 Aug 2017 18:24:30 +0200 Subject: [PATCH 1/2] Add a couple of samples for the end-users. --- EntityFrameworkCore.FirebirdSQL.sln | 24 +++- .../EFCore.Firebird.AspNetSample.sln | 25 ++++ .../Controllers/Authors2Controller.cs | 70 ++++++++++ .../Controllers/AuthorsController.cs | 125 ++++++++++++++++++ .../EFCore.Firebird.AspNetSample.csproj | 35 +++++ .../20170825235439_CreateDatabase.Designer.cs | 64 +++++++++ .../20170825235439_CreateDatabase.cs | 61 +++++++++ .../20170827214020_AddSampleData.Designer.cs | 64 +++++++++ .../20170827214020_AddSampleData.cs | 26 ++++ .../SampleModelsContextModelSnapshot.cs | 63 +++++++++ .../Models/SampleModels.cs | 41 ++++++ .../EFCore.Firebird.AspNetSample/Program.cs | 22 +++ .../Properties/launchSettings.json | 29 ++++ .../EFCore.Firebird.AspNetSample/Startup.cs | 45 +++++++ .../appsettings.Development.json | 10 ++ .../appsettings.json | 10 ++ .../wwwroot/css/site.css | 43 ++++++ .../wwwroot/js/site.js | 1 + Samples/AspNetCore/README.md | 27 ++++ Samples/ScaffoldingConsoleApp/Program.cs | 12 ++ Samples/ScaffoldingConsoleApp/README.md | 12 ++ .../ScaffoldingConsoleApp.csproj | 15 +++ .../Scripts/DatabaseScript.sql | 78 +++++++++++ 23 files changed, 901 insertions(+), 1 deletion(-) create mode 100644 Samples/AspNetCore/EFCore.Firebird.AspNetSample.sln create mode 100644 Samples/AspNetCore/EFCore.Firebird.AspNetSample/Controllers/Authors2Controller.cs create mode 100644 Samples/AspNetCore/EFCore.Firebird.AspNetSample/Controllers/AuthorsController.cs create mode 100644 Samples/AspNetCore/EFCore.Firebird.AspNetSample/EFCore.Firebird.AspNetSample.csproj create mode 100644 Samples/AspNetCore/EFCore.Firebird.AspNetSample/Migrations/20170825235439_CreateDatabase.Designer.cs create mode 100644 Samples/AspNetCore/EFCore.Firebird.AspNetSample/Migrations/20170825235439_CreateDatabase.cs create mode 100644 Samples/AspNetCore/EFCore.Firebird.AspNetSample/Migrations/20170827214020_AddSampleData.Designer.cs create mode 100644 Samples/AspNetCore/EFCore.Firebird.AspNetSample/Migrations/20170827214020_AddSampleData.cs create mode 100644 Samples/AspNetCore/EFCore.Firebird.AspNetSample/Migrations/SampleModelsContextModelSnapshot.cs create mode 100644 Samples/AspNetCore/EFCore.Firebird.AspNetSample/Models/SampleModels.cs create mode 100644 Samples/AspNetCore/EFCore.Firebird.AspNetSample/Program.cs create mode 100644 Samples/AspNetCore/EFCore.Firebird.AspNetSample/Properties/launchSettings.json create mode 100644 Samples/AspNetCore/EFCore.Firebird.AspNetSample/Startup.cs create mode 100644 Samples/AspNetCore/EFCore.Firebird.AspNetSample/appsettings.Development.json create mode 100644 Samples/AspNetCore/EFCore.Firebird.AspNetSample/appsettings.json create mode 100644 Samples/AspNetCore/EFCore.Firebird.AspNetSample/wwwroot/css/site.css create mode 100644 Samples/AspNetCore/EFCore.Firebird.AspNetSample/wwwroot/js/site.js create mode 100644 Samples/AspNetCore/README.md create mode 100644 Samples/ScaffoldingConsoleApp/Program.cs create mode 100644 Samples/ScaffoldingConsoleApp/README.md create mode 100644 Samples/ScaffoldingConsoleApp/ScaffoldingConsoleApp.csproj create mode 100644 Samples/ScaffoldingConsoleApp/Scripts/DatabaseScript.sql diff --git a/EntityFrameworkCore.FirebirdSQL.sln b/EntityFrameworkCore.FirebirdSQL.sln index a0ea257..5f41aa8 100644 --- a/EntityFrameworkCore.FirebirdSQL.sln +++ b/EntityFrameworkCore.FirebirdSQL.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 -VisualStudioVersion = 15.0.26730.3 +VisualStudioVersion = 15.0.26730.12 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EFCore.FirebirdSQL", "EFCore.FirebirdSQL\EFCore.FirebirdSQL.csproj", "{C725AC99-64C8-4CBF-B01F-094D5837BC58}" EndProject @@ -9,6 +9,16 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EFCore.FirebirdSQL.Console. EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{48F660F0-8ED4-4688-A565-0E2CEAF15A81}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Samples", "Samples", "{61F7E35E-FCDB-499E-B527-85A2D268F227}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "AspNetCore", "AspNetCore", "{641AAD0D-B815-41BE-A5E6-32C941D7620A}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ScaffoldingConsoleApp", "ScaffoldingConsoleApp", "{DA2BBCEF-5423-4437-9157-D6A788F5DA2F}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ScaffoldingConsoleApp", "Samples\ScaffoldingConsoleApp\ScaffoldingConsoleApp.csproj", "{DC5FD402-9857-4917-9B95-EE1E806E8B8B}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EFCore.Firebird.AspNetSample", "Samples\AspNetCore\EFCore.Firebird.AspNetSample\EFCore.Firebird.AspNetSample.csproj", "{DF2CF326-D401-4394-9A3A-56F244430EEF}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -23,12 +33,24 @@ Global {E1786F5D-5D2C-4231-BEFA-A563F075BD8B}.Debug|Any CPU.Build.0 = Debug|Any CPU {E1786F5D-5D2C-4231-BEFA-A563F075BD8B}.Release|Any CPU.ActiveCfg = Release|Any CPU {E1786F5D-5D2C-4231-BEFA-A563F075BD8B}.Release|Any CPU.Build.0 = Release|Any CPU + {DC5FD402-9857-4917-9B95-EE1E806E8B8B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {DC5FD402-9857-4917-9B95-EE1E806E8B8B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DC5FD402-9857-4917-9B95-EE1E806E8B8B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {DC5FD402-9857-4917-9B95-EE1E806E8B8B}.Release|Any CPU.Build.0 = Release|Any CPU + {DF2CF326-D401-4394-9A3A-56F244430EEF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {DF2CF326-D401-4394-9A3A-56F244430EEF}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DF2CF326-D401-4394-9A3A-56F244430EEF}.Release|Any CPU.ActiveCfg = Release|Any CPU + {DF2CF326-D401-4394-9A3A-56F244430EEF}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection GlobalSection(NestedProjects) = preSolution {E1786F5D-5D2C-4231-BEFA-A563F075BD8B} = {48F660F0-8ED4-4688-A565-0E2CEAF15A81} + {641AAD0D-B815-41BE-A5E6-32C941D7620A} = {61F7E35E-FCDB-499E-B527-85A2D268F227} + {DA2BBCEF-5423-4437-9157-D6A788F5DA2F} = {61F7E35E-FCDB-499E-B527-85A2D268F227} + {DC5FD402-9857-4917-9B95-EE1E806E8B8B} = {DA2BBCEF-5423-4437-9157-D6A788F5DA2F} + {DF2CF326-D401-4394-9A3A-56F244430EEF} = {641AAD0D-B815-41BE-A5E6-32C941D7620A} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {CCB461D4-B163-4511-8434-CE0C357FDC74} diff --git a/Samples/AspNetCore/EFCore.Firebird.AspNetSample.sln b/Samples/AspNetCore/EFCore.Firebird.AspNetSample.sln new file mode 100644 index 0000000..52c2448 --- /dev/null +++ b/Samples/AspNetCore/EFCore.Firebird.AspNetSample.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.26730.10 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EFCore.Firebird.AspNetSample", "EFCore.Firebird.AspNetSample\EFCore.Firebird.AspNetSample.csproj", "{A0E6AA62-FFB2-415B-A70C-CA99939537D3}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {A0E6AA62-FFB2-415B-A70C-CA99939537D3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A0E6AA62-FFB2-415B-A70C-CA99939537D3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A0E6AA62-FFB2-415B-A70C-CA99939537D3}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A0E6AA62-FFB2-415B-A70C-CA99939537D3}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {5420DE74-243E-4CC7-8937-FA1BEDB2A622} + EndGlobalSection +EndGlobal diff --git a/Samples/AspNetCore/EFCore.Firebird.AspNetSample/Controllers/Authors2Controller.cs b/Samples/AspNetCore/EFCore.Firebird.AspNetSample/Controllers/Authors2Controller.cs new file mode 100644 index 0000000..0ee20f2 --- /dev/null +++ b/Samples/AspNetCore/EFCore.Firebird.AspNetSample/Controllers/Authors2Controller.cs @@ -0,0 +1,70 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; +using SouchProd.EFCore.Firebird.AspNetSample.Models; +using Microsoft.EntityFrameworkCore; + +namespace SouchProd.EFCore.Firebird.AspNetSample.Controllers +{ + [Route("api/[controller]")] + public class Authors2Controller : Controller + { + private SampleModelsContext _dbContext; + + /// + /// Controller constructor + /// + /// Database context from the Dependency injection + public Authors2Controller(SampleModelsContext dbContext) + { + _dbContext = dbContext; + + // Perform the pending migrations automatically + _dbContext.Database.Migrate(); + } + + // GET api/authors + [HttpGet] + public async Task> GetAsync() + { + return await _dbContext.Authors.AsNoTracking().ToListAsync(); + } + + // GET api/authors/5 + [HttpGet("{id}")] + public async Task Get(int id) + { + return await _dbContext.Authors.FirstOrDefaultAsync(x => x.AuthorId.Equals(id)); + } + + // POST api/authors + [HttpPost] + public void Post([FromBody]Author value) + { + _dbContext.Authors.Add(value); + _dbContext.SaveChanges(); + } + + // PUT api/authors/5 + [HttpPut("{id}")] + public void Put(int id, [FromBody]Author value) + { + _dbContext.Authors.Update(value); + _dbContext.SaveChanges(); + } + + // DELETE api/authors/5 + [HttpDelete("{id}")] + public void Delete(int id) + { + var entity = _dbContext.Authors.FirstOrDefault(x => x.AuthorId.Equals(id)); + if (entity != null) + { + _dbContext.Authors.Remove(entity); + _dbContext.SaveChanges(); + } + } + } +} diff --git a/Samples/AspNetCore/EFCore.Firebird.AspNetSample/Controllers/AuthorsController.cs b/Samples/AspNetCore/EFCore.Firebird.AspNetSample/Controllers/AuthorsController.cs new file mode 100644 index 0000000..4938cee --- /dev/null +++ b/Samples/AspNetCore/EFCore.Firebird.AspNetSample/Controllers/AuthorsController.cs @@ -0,0 +1,125 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; +using SouchProd.EFCore.Firebird.AspNetSample.Models; + +namespace EFCore.Firebird.AspNetSample.Controllers +{ + [Produces("application/json")] + [Route("api/Authors")] + public class AuthorsController : Controller + { + private readonly SampleModelsContext _context; + + public AuthorsController(SampleModelsContext context) + { + _context = context; + } + + // GET: api/Authors + [HttpGet] + public IEnumerable GetAuthors() + { + return _context.Authors; + } + + // GET: api/Authors/5 + [HttpGet("{id}")] + public async Task GetAuthor([FromRoute] int id) + { + if (!ModelState.IsValid) + { + return BadRequest(ModelState); + } + + var author = await _context.Authors.SingleOrDefaultAsync(m => m.AuthorId == id); + + if (author == null) + { + return NotFound(); + } + + return Ok(author); + } + + // PUT: api/Authors/5 + [HttpPut("{id}")] + public async Task PutAuthor([FromRoute] int id, [FromBody] Author author) + { + if (!ModelState.IsValid) + { + return BadRequest(ModelState); + } + + if (id != author.AuthorId) + { + return BadRequest(); + } + + _context.Entry(author).State = EntityState.Modified; + + try + { + await _context.SaveChangesAsync(); + } + catch (DbUpdateConcurrencyException) + { + if (!AuthorExists(id)) + { + return NotFound(); + } + else + { + throw; + } + } + + return NoContent(); + } + + // POST: api/Authors + [HttpPost] + public async Task PostAuthor([FromBody] Author author) + { + if (!ModelState.IsValid) + { + return BadRequest(ModelState); + } + + _context.Authors.Add(author); + await _context.SaveChangesAsync(); + + return CreatedAtAction("GetAuthor", new { id = author.AuthorId }, author); + } + + // DELETE: api/Authors/5 + [HttpDelete("{id}")] + public async Task DeleteAuthor([FromRoute] int id) + { + if (!ModelState.IsValid) + { + return BadRequest(ModelState); + } + + var author = await _context.Authors.SingleOrDefaultAsync(m => m.AuthorId == id); + if (author == null) + { + return NotFound(); + } + + _context.Authors.Remove(author); + await _context.SaveChangesAsync(); + + return Ok(author); + } + + private bool AuthorExists(int id) + { + return _context.Authors.Any(e => e.AuthorId == id); + } + } +} \ No newline at end of file diff --git a/Samples/AspNetCore/EFCore.Firebird.AspNetSample/EFCore.Firebird.AspNetSample.csproj b/Samples/AspNetCore/EFCore.Firebird.AspNetSample/EFCore.Firebird.AspNetSample.csproj new file mode 100644 index 0000000..47556e2 --- /dev/null +++ b/Samples/AspNetCore/EFCore.Firebird.AspNetSample/EFCore.Firebird.AspNetSample.csproj @@ -0,0 +1,35 @@ + + + + netcoreapp2.0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Samples/AspNetCore/EFCore.Firebird.AspNetSample/Migrations/20170825235439_CreateDatabase.Designer.cs b/Samples/AspNetCore/EFCore.Firebird.AspNetSample/Migrations/20170825235439_CreateDatabase.Designer.cs new file mode 100644 index 0000000..c8c8edc --- /dev/null +++ b/Samples/AspNetCore/EFCore.Firebird.AspNetSample/Migrations/20170825235439_CreateDatabase.Designer.cs @@ -0,0 +1,64 @@ +// +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage; +using Microsoft.EntityFrameworkCore.Storage.Internal; +using SouchProd.EFCore.Firebird.AspNetSample.Models; +using System; + +namespace SouchProd.EFCore.Firebird.AspNetSample.Migrations +{ + [DbContext(typeof(SampleModelsContext))] + [Migration("20170825235439_CreateDatabase")] + partial class CreateDatabase + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("Firebird:ValueGenerationStrategy", FbValueGenerationStrategy.IdentityColumn) + .HasAnnotation("ProductVersion", "2.0.0-rtm-26452"); + + modelBuilder.Entity("SouchProd.EFCore.Firebird.AspNetSample.Models.Author", b => + { + b.Property("AuthorId") + .ValueGeneratedOnAdd(); + + b.Property("FirstName"); + + b.Property("LastName"); + + b.HasKey("AuthorId"); + + b.ToTable("Authors"); + }); + + modelBuilder.Entity("SouchProd.EFCore.Firebird.AspNetSample.Models.Book", b => + { + b.Property("BookId") + .ValueGeneratedOnAdd(); + + b.Property("AuthorId"); + + b.Property("Title"); + + b.HasKey("BookId"); + + b.HasIndex("AuthorId"); + + b.ToTable("Books"); + }); + + modelBuilder.Entity("SouchProd.EFCore.Firebird.AspNetSample.Models.Book", b => + { + b.HasOne("SouchProd.EFCore.Firebird.AspNetSample.Models.Author", "Author") + .WithMany("Books") + .HasForeignKey("AuthorId") + .OnDelete(DeleteBehavior.Cascade); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Samples/AspNetCore/EFCore.Firebird.AspNetSample/Migrations/20170825235439_CreateDatabase.cs b/Samples/AspNetCore/EFCore.Firebird.AspNetSample/Migrations/20170825235439_CreateDatabase.cs new file mode 100644 index 0000000..b735073 --- /dev/null +++ b/Samples/AspNetCore/EFCore.Firebird.AspNetSample/Migrations/20170825235439_CreateDatabase.cs @@ -0,0 +1,61 @@ +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using System; +using System.Collections.Generic; + +namespace SouchProd.EFCore.Firebird.AspNetSample.Migrations +{ + public partial class CreateDatabase : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Authors", + columns: table => new + { + AuthorId = table.Column(type: "integer", nullable: false) + .Annotation("Firebird:ValueGenerationStrategy", FbValueGenerationStrategy.IdentityColumn), + FirstName = table.Column(type: "varchar(4000)", nullable: true), + LastName = table.Column(type: "varchar(4000)", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Authors", x => x.AuthorId); + }); + + migrationBuilder.CreateTable( + name: "Books", + columns: table => new + { + BookId = table.Column(type: "integer", nullable: false) + .Annotation("Firebird:ValueGenerationStrategy", FbValueGenerationStrategy.IdentityColumn), + AuthorId = table.Column(type: "integer", nullable: false), + Title = table.Column(type: "varchar(4000)", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Books", x => x.BookId); + table.ForeignKey( + name: "FK_Books_Authors_AuthorId", + column: x => x.AuthorId, + principalTable: "Authors", + principalColumn: "AuthorId", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_Books_AuthorId", + table: "Books", + column: "AuthorId"); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Books"); + + migrationBuilder.DropTable( + name: "Authors"); + } + } +} diff --git a/Samples/AspNetCore/EFCore.Firebird.AspNetSample/Migrations/20170827214020_AddSampleData.Designer.cs b/Samples/AspNetCore/EFCore.Firebird.AspNetSample/Migrations/20170827214020_AddSampleData.Designer.cs new file mode 100644 index 0000000..7fce83b --- /dev/null +++ b/Samples/AspNetCore/EFCore.Firebird.AspNetSample/Migrations/20170827214020_AddSampleData.Designer.cs @@ -0,0 +1,64 @@ +// +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage; +using Microsoft.EntityFrameworkCore.Storage.Internal; +using SouchProd.EFCore.Firebird.AspNetSample.Models; +using System; + +namespace SouchProd.EFCore.Firebird.AspNetSample.Migrations +{ + [DbContext(typeof(SampleModelsContext))] + [Migration("20170827214020_AddSampleData")] + partial class AddSampleData + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("Firebird:ValueGenerationStrategy", FbValueGenerationStrategy.IdentityColumn) + .HasAnnotation("ProductVersion", "2.0.0-rtm-26452"); + + modelBuilder.Entity("SouchProd.EFCore.Firebird.AspNetSample.Models.Author", b => + { + b.Property("AuthorId") + .ValueGeneratedOnAdd(); + + b.Property("FirstName"); + + b.Property("LastName"); + + b.HasKey("AuthorId"); + + b.ToTable("Authors"); + }); + + modelBuilder.Entity("SouchProd.EFCore.Firebird.AspNetSample.Models.Book", b => + { + b.Property("BookId") + .ValueGeneratedOnAdd(); + + b.Property("AuthorId"); + + b.Property("Title"); + + b.HasKey("BookId"); + + b.HasIndex("AuthorId"); + + b.ToTable("Books"); + }); + + modelBuilder.Entity("SouchProd.EFCore.Firebird.AspNetSample.Models.Book", b => + { + b.HasOne("SouchProd.EFCore.Firebird.AspNetSample.Models.Author", "Author") + .WithMany("Books") + .HasForeignKey("AuthorId") + .OnDelete(DeleteBehavior.Cascade); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Samples/AspNetCore/EFCore.Firebird.AspNetSample/Migrations/20170827214020_AddSampleData.cs b/Samples/AspNetCore/EFCore.Firebird.AspNetSample/Migrations/20170827214020_AddSampleData.cs new file mode 100644 index 0000000..996a368 --- /dev/null +++ b/Samples/AspNetCore/EFCore.Firebird.AspNetSample/Migrations/20170827214020_AddSampleData.cs @@ -0,0 +1,26 @@ +using Microsoft.EntityFrameworkCore.Migrations; +using System; +using System.Collections.Generic; + +namespace SouchProd.EFCore.Firebird.AspNetSample.Migrations +{ + public partial class AddSampleData : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.Sql("INSERT INTO Authors (AuthorId, Firstname, Lastname) VALUES (1, 'Stephen', 'King');"); + migrationBuilder.Sql("INSERT INTO Authors (AuthorId, Firstname, Lastname) VALUES (2, 'Isaac', 'Asimov');"); + migrationBuilder.Sql("INSERT INTO Books (BookId, AuthorId, Title) VALUES (1, 1, 'The Shining');"); + migrationBuilder.Sql("INSERT INTO Books (BookId, AuthorId, Title) VALUES (2, 1, 'Black House');"); + migrationBuilder.Sql("INSERT INTO Books (BookId, AuthorId, Title) VALUES (3, 1, 'Cujo');"); + migrationBuilder.Sql("INSERT INTO Books (BookId, AuthorId, Title) VALUES (4, 2, 'Prelude to Foundation');"); + migrationBuilder.Sql("INSERT INTO Books (BookId, AuthorId, Title) VALUES (5, 2, 'Foundation');"); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.Sql("DELETE FROM Books"); + migrationBuilder.Sql("DELETE FROM Authors;"); + } + } +} diff --git a/Samples/AspNetCore/EFCore.Firebird.AspNetSample/Migrations/SampleModelsContextModelSnapshot.cs b/Samples/AspNetCore/EFCore.Firebird.AspNetSample/Migrations/SampleModelsContextModelSnapshot.cs new file mode 100644 index 0000000..9ea65b4 --- /dev/null +++ b/Samples/AspNetCore/EFCore.Firebird.AspNetSample/Migrations/SampleModelsContextModelSnapshot.cs @@ -0,0 +1,63 @@ +// +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage; +using Microsoft.EntityFrameworkCore.Storage.Internal; +using SouchProd.EFCore.Firebird.AspNetSample.Models; +using System; + +namespace SouchProd.EFCore.Firebird.AspNetSample.Migrations +{ + [DbContext(typeof(SampleModelsContext))] + partial class SampleModelsContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("Firebird:ValueGenerationStrategy", FbValueGenerationStrategy.IdentityColumn) + .HasAnnotation("ProductVersion", "2.0.0-rtm-26452"); + + modelBuilder.Entity("SouchProd.EFCore.Firebird.AspNetSample.Models.Author", b => + { + b.Property("AuthorId") + .ValueGeneratedOnAdd(); + + b.Property("FirstName"); + + b.Property("LastName"); + + b.HasKey("AuthorId"); + + b.ToTable("Authors"); + }); + + modelBuilder.Entity("SouchProd.EFCore.Firebird.AspNetSample.Models.Book", b => + { + b.Property("BookId") + .ValueGeneratedOnAdd(); + + b.Property("AuthorId"); + + b.Property("Title"); + + b.HasKey("BookId"); + + b.HasIndex("AuthorId"); + + b.ToTable("Books"); + }); + + modelBuilder.Entity("SouchProd.EFCore.Firebird.AspNetSample.Models.Book", b => + { + b.HasOne("SouchProd.EFCore.Firebird.AspNetSample.Models.Author", "Author") + .WithMany("Books") + .HasForeignKey("AuthorId") + .OnDelete(DeleteBehavior.Cascade); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Samples/AspNetCore/EFCore.Firebird.AspNetSample/Models/SampleModels.cs b/Samples/AspNetCore/EFCore.Firebird.AspNetSample/Models/SampleModels.cs new file mode 100644 index 0000000..18b4cb0 --- /dev/null +++ b/Samples/AspNetCore/EFCore.Firebird.AspNetSample/Models/SampleModels.cs @@ -0,0 +1,41 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Configuration; +using System.Collections.Generic; +using System.IO; + +namespace SouchProd.EFCore.Firebird.AspNetSample.Models +{ + public class SampleModelsContext : DbContext + { + public DbSet Books { get; set; } + public DbSet Authors { get; set; } + + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { + var Configuration = new ConfigurationBuilder() + .SetBasePath(Directory.GetCurrentDirectory()) + .AddJsonFile("appsettings.json") + .Build(); + + optionsBuilder.UseFirebirdSql(Configuration["ConnectionString"]); + } + + } + + public class Author + { + public int AuthorId { get; set; } + public string FirstName { get; set; } + public string LastName { get; set; } + public ICollection Books { get; set; } + } + + public class Book + { + public int BookId { get; set; } + public string Title { get; set; } + public int AuthorId { get; set; } + public Author Author { get; set; } + } + +} diff --git a/Samples/AspNetCore/EFCore.Firebird.AspNetSample/Program.cs b/Samples/AspNetCore/EFCore.Firebird.AspNetSample/Program.cs new file mode 100644 index 0000000..915b402 --- /dev/null +++ b/Samples/AspNetCore/EFCore.Firebird.AspNetSample/Program.cs @@ -0,0 +1,22 @@ +using System.IO; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; + +namespace SouchProd.EFCore.Firebird.AspNetSample +{ + public class Program + { + public static void Main(string[] args) + { + var host = new WebHostBuilder() + .UseKestrel() + .UseContentRoot(Directory.GetCurrentDirectory()) + .UseIISIntegration() + .UseStartup() + .UseApplicationInsights() + .Build(); + + host.Run(); + } + } +} diff --git a/Samples/AspNetCore/EFCore.Firebird.AspNetSample/Properties/launchSettings.json b/Samples/AspNetCore/EFCore.Firebird.AspNetSample/Properties/launchSettings.json new file mode 100644 index 0000000..af94a8a --- /dev/null +++ b/Samples/AspNetCore/EFCore.Firebird.AspNetSample/Properties/launchSettings.json @@ -0,0 +1,29 @@ +{ + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:55471/", + "sslPort": 0 + } + }, + "profiles": { + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "api/authors", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "SouchProd.EFCore.Firebird.AspNetSample": { + "commandName": "Project", + "launchBrowser": true, + "launchUrl": "api/authors", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "applicationUrl": "http://localhost:55472/" + } + } +} diff --git a/Samples/AspNetCore/EFCore.Firebird.AspNetSample/Startup.cs b/Samples/AspNetCore/EFCore.Firebird.AspNetSample/Startup.cs new file mode 100644 index 0000000..8e9ee9d --- /dev/null +++ b/Samples/AspNetCore/EFCore.Firebird.AspNetSample/Startup.cs @@ -0,0 +1,45 @@ +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using SouchProd.EFCore.Firebird.AspNetSample.Models; +using Microsoft.EntityFrameworkCore; + +namespace SouchProd.EFCore.Firebird.AspNetSample +{ + public class Startup + { + public Startup(IHostingEnvironment env) + { + var builder = new ConfigurationBuilder() + .SetBasePath(env.ContentRootPath) + .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) + .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true) + .AddEnvironmentVariables(); + Configuration = builder.Build(); + } + + public IConfigurationRoot Configuration { get; } + + // This method gets called by the runtime. Use this method to add services to the container. + public void ConfigureServices(IServiceCollection services) + { + + // Add the dbcontext to provide the capability to consume it easily in the controllers via the DI. + services.AddDbContext(); + + // Add framework services. + services.AddMvc(); + } + + // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. + public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) + { + loggerFactory.AddConsole(Configuration.GetSection("Logging")); + loggerFactory.AddDebug(); + + app.UseMvc(); + } + } +} diff --git a/Samples/AspNetCore/EFCore.Firebird.AspNetSample/appsettings.Development.json b/Samples/AspNetCore/EFCore.Firebird.AspNetSample/appsettings.Development.json new file mode 100644 index 0000000..fa8ce71 --- /dev/null +++ b/Samples/AspNetCore/EFCore.Firebird.AspNetSample/appsettings.Development.json @@ -0,0 +1,10 @@ +{ + "Logging": { + "IncludeScopes": false, + "LogLevel": { + "Default": "Debug", + "System": "Information", + "Microsoft": "Information" + } + } +} diff --git a/Samples/AspNetCore/EFCore.Firebird.AspNetSample/appsettings.json b/Samples/AspNetCore/EFCore.Firebird.AspNetSample/appsettings.json new file mode 100644 index 0000000..4af27cf --- /dev/null +++ b/Samples/AspNetCore/EFCore.Firebird.AspNetSample/appsettings.json @@ -0,0 +1,10 @@ +{ + "Logging": { + "IncludeScopes": false, + "LogLevel": { + "Default": "Trace", + "Microsoft": "Trace" + } + }, + "ConnectionString": "User=SYSDBA;Password=masterkey;Database=D:\\EfCoreTest.fdb;DataSource=localhost;Port=3050;Dialect=3;Charset=UTF8;Role=;Connection lifetime=15;Pooling=true;MinPoolSize=0;MaxPoolSize=50;Packet Size=8192;ServerType=0;" +} diff --git a/Samples/AspNetCore/EFCore.Firebird.AspNetSample/wwwroot/css/site.css b/Samples/AspNetCore/EFCore.Firebird.AspNetSample/wwwroot/css/site.css new file mode 100644 index 0000000..c778be1 --- /dev/null +++ b/Samples/AspNetCore/EFCore.Firebird.AspNetSample/wwwroot/css/site.css @@ -0,0 +1,43 @@ +body { + padding-top: 50px; + padding-bottom: 20px; +} + +/* Set padding to keep content from hitting the edges */ +.body-content { + padding-left: 15px; + padding-right: 15px; +} + +/* Set width on the form input elements since they're 100% wide by default */ +input, +select, +textarea { + max-width: 280px; +} + +/* styles for validation helpers */ +.field-validation-error { + color: #b94a48; +} + +.field-validation-valid { + display: none; +} + +input.input-validation-error { + border: 1px solid #b94a48; +} + +input[type="checkbox"].input-validation-error { + border: 0 none; +} + +.validation-summary-errors { + color: #b94a48; +} + +.validation-summary-valid { + display: none; +} + diff --git a/Samples/AspNetCore/EFCore.Firebird.AspNetSample/wwwroot/js/site.js b/Samples/AspNetCore/EFCore.Firebird.AspNetSample/wwwroot/js/site.js new file mode 100644 index 0000000..3c7ee9d --- /dev/null +++ b/Samples/AspNetCore/EFCore.Firebird.AspNetSample/wwwroot/js/site.js @@ -0,0 +1 @@ +// Write your Javascript code. \ No newline at end of file diff --git a/Samples/AspNetCore/README.md b/Samples/AspNetCore/README.md new file mode 100644 index 0000000..c0662eb --- /dev/null +++ b/Samples/AspNetCore/README.md @@ -0,0 +1,27 @@ +# Asp.Net Core Sample Projet + +This very basic sample demonstrate the usage of the [Entity Framework Core Provider for Firebird](https://github.com/souchprod/SouchProd.EntityFrameworkCore.Firebird). + +# Configuration + +* Create a Firebird database + +* Edit the ConnectionString in the appsettings.json file to match your newly create database. + +* Use the [migration](http://www.learnentityframeworkcore.com/migrations#applying-a-migration) capability to restore the database schema and default data : + + * Simply start the application, `_dbContext.Database.Migrate()` is automatically called and will apply all the pending migrations. + + * [Command line] + `dotnet ef database update` + + * [Package Manager Console] + `update-database` + +# Usage + +- GET /api/autors list the authors +- GET /api/autors/1 return the author id 1. +- POST api/authors add the embeded item to the db. +- PUT api/authors/1 update the specified item with then embeded item. +- DELETE api/authors/5 delete the specified item from the db. diff --git a/Samples/ScaffoldingConsoleApp/Program.cs b/Samples/ScaffoldingConsoleApp/Program.cs new file mode 100644 index 0000000..16b9bdc --- /dev/null +++ b/Samples/ScaffoldingConsoleApp/Program.cs @@ -0,0 +1,12 @@ +using System; + +namespace ScaffoldingConsoleApp +{ + class Program + { + static void Main(string[] args) + { + Console.WriteLine("Hello World!"); + } + } +} diff --git a/Samples/ScaffoldingConsoleApp/README.md b/Samples/ScaffoldingConsoleApp/README.md new file mode 100644 index 0000000..88a7463 --- /dev/null +++ b/Samples/ScaffoldingConsoleApp/README.md @@ -0,0 +1,12 @@ +# Scaffolding Sample + +This very basic console app demonstrate & test the Scaffolding capability of the Firebird provider. + +### Configuration + +1. Create the sample database using the provided script, adjust the filename & credentials before. +2. Using the Package Manager Console in Visual Studio (ensur that the correct project is selected), execute the following command. You may adjust the database filenema and location, as well as the default password. + + ``Scaffold-DbContext "User=SYSDBA;Password=masterkey;Database=D:/ScaffoldTestDb.fdb;DataSource=127.0.0.1;Port=3050;Dialect=3;Charset=UTF8;Role=;Connection lifetime=15;Pooling=true;MinPoolSize=0;MaxPoolSize=50;Packet Size=8192;ServerType=0;" "souchprod.EntityFrameworkCore.Firebird" -OutputDir Entities -Context "SampleDbContext" -DataAnnotations -force -verbose`` + +3. A folder "Entities" will be automatically created, it will contains the generated models and the DBContext, ready to be conssumed. \ No newline at end of file diff --git a/Samples/ScaffoldingConsoleApp/ScaffoldingConsoleApp.csproj b/Samples/ScaffoldingConsoleApp/ScaffoldingConsoleApp.csproj new file mode 100644 index 0000000..e2ea2bf --- /dev/null +++ b/Samples/ScaffoldingConsoleApp/ScaffoldingConsoleApp.csproj @@ -0,0 +1,15 @@ + + + + Exe + netcoreapp2.0 + + + + + + + + + + diff --git a/Samples/ScaffoldingConsoleApp/Scripts/DatabaseScript.sql b/Samples/ScaffoldingConsoleApp/Scripts/DatabaseScript.sql new file mode 100644 index 0000000..3c20c69 --- /dev/null +++ b/Samples/ScaffoldingConsoleApp/Scripts/DatabaseScript.sql @@ -0,0 +1,78 @@ +/******************************************************************************/ +/*** Generated by IBExpert 2013.2.20.1 29/08/2017 12:24:01 ***/ +/******************************************************************************/ + +SET SQL DIALECT 3; + +SET NAMES UTF8; + +CREATE DATABASE '127.0.0.1:C:\ScaffoldTestDb.fdb' +USER 'SYSDBA' PASSWORD 'masterkey' +PAGE_SIZE 16384 +DEFAULT CHARACTER SET UTF8 COLLATION UTF8; + +/******************************************************************************/ +/*** Generators ***/ +/******************************************************************************/ + +CREATE GENERATOR GEN_SAMPLETABLE1_ID; +SET GENERATOR GEN_SAMPLETABLE1_ID TO 0; + +/******************************************************************************/ +/*** Tables ***/ +/******************************************************************************/ + +CREATE TABLE SAMPLETABLE1 ( + ID INTEGER NOT NULL, + FIELDINT INTEGER, + FIELDSTR VARCHAR(255) +); + +CREATE TABLE SAMPLETABLE2 ( + ID INTEGER NOT NULL, + SAMPLETABLE1ID INTEGER NOT NULL, + FIELDSMALLINT SMALLINT, + FIELDBIGINT BIGINT DEFAULT 42, + FIELDNUM NUMERIC(18,4), + FIELDMEMO BLOB SUB_TYPE 1 SEGMENT SIZE 80, + FIELDBLOB BLOB SUB_TYPE 0 SEGMENT SIZE 80, + TYPETIMESTAMP TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + FIELDDATE DATE, + FIELDTIME TIME, + FIELDGUID CHAR(36) +); + +/******************************************************************************/ +/*** Primary Keys ***/ +/******************************************************************************/ + +ALTER TABLE SAMPLETABLE1 ADD CONSTRAINT PK_SAMPLETABLE1 PRIMARY KEY (ID); +ALTER TABLE SAMPLETABLE2 ADD CONSTRAINT PK_SAMPLETABLE2 PRIMARY KEY (ID); + +/******************************************************************************/ +/*** Foreign Keys ***/ +/******************************************************************************/ + +ALTER TABLE SAMPLETABLE2 ADD CONSTRAINT FK_SAMPLETABLE2_1 FOREIGN KEY (SAMPLETABLE1ID) REFERENCES SAMPLETABLE1 (ID) ON DELETE CASCADE ON UPDATE CASCADE; + +/******************************************************************************/ +/*** Triggers ***/ +/******************************************************************************/ + +SET TERM ^ ; + +/******************************************************************************/ +/*** Triggers for tables ***/ +/******************************************************************************/ + +/* Trigger: SAMPLETABLE1_BI */ +CREATE TRIGGER SAMPLETABLE1_BI FOR SAMPLETABLE1 +ACTIVE BEFORE INSERT POSITION 0 +as +begin + if (new.id is null) then + new.id = gen_id(gen_sampletable1_id,1); +end +^ + +SET TERM ; ^ From ac6094eed0ab9c256b0b5e140862f12250a3f3ae Mon Sep 17 00:00:00 2001 From: "Jean.R" Date: Wed, 30 Aug 2017 18:27:44 +0200 Subject: [PATCH 2/2] Cleanup --- .../wwwroot/css/site.css | 43 ------------------- .../wwwroot/js/site.js | 1 - 2 files changed, 44 deletions(-) delete mode 100644 Samples/AspNetCore/EFCore.Firebird.AspNetSample/wwwroot/css/site.css delete mode 100644 Samples/AspNetCore/EFCore.Firebird.AspNetSample/wwwroot/js/site.js diff --git a/Samples/AspNetCore/EFCore.Firebird.AspNetSample/wwwroot/css/site.css b/Samples/AspNetCore/EFCore.Firebird.AspNetSample/wwwroot/css/site.css deleted file mode 100644 index c778be1..0000000 --- a/Samples/AspNetCore/EFCore.Firebird.AspNetSample/wwwroot/css/site.css +++ /dev/null @@ -1,43 +0,0 @@ -body { - padding-top: 50px; - padding-bottom: 20px; -} - -/* Set padding to keep content from hitting the edges */ -.body-content { - padding-left: 15px; - padding-right: 15px; -} - -/* Set width on the form input elements since they're 100% wide by default */ -input, -select, -textarea { - max-width: 280px; -} - -/* styles for validation helpers */ -.field-validation-error { - color: #b94a48; -} - -.field-validation-valid { - display: none; -} - -input.input-validation-error { - border: 1px solid #b94a48; -} - -input[type="checkbox"].input-validation-error { - border: 0 none; -} - -.validation-summary-errors { - color: #b94a48; -} - -.validation-summary-valid { - display: none; -} - diff --git a/Samples/AspNetCore/EFCore.Firebird.AspNetSample/wwwroot/js/site.js b/Samples/AspNetCore/EFCore.Firebird.AspNetSample/wwwroot/js/site.js deleted file mode 100644 index 3c7ee9d..0000000 --- a/Samples/AspNetCore/EFCore.Firebird.AspNetSample/wwwroot/js/site.js +++ /dev/null @@ -1 +0,0 @@ -// Write your Javascript code. \ No newline at end of file