diff --git a/COA.EnterpriseServices.DataAccess.EntityFramework/EntityDataAccess.cs b/COA.EnterpriseServices.DataAccess.EntityFramework/EntityDataAccess.cs index 94e1da0..57c5590 100644 --- a/COA.EnterpriseServices.DataAccess.EntityFramework/EntityDataAccess.cs +++ b/COA.EnterpriseServices.DataAccess.EntityFramework/EntityDataAccess.cs @@ -1,30 +1,57 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Linq.Expressions; using System.Text; namespace COA.EnterpriseServices.DataAccess.EntityFramework { - public class EntityDataAccess : IDataAccess where T : IRecord + public class EntityDataAccess : IDataAccess where T : class, IRecord { public bool Add(T item) { - throw new NotImplementedException(); + using (var context = new QuickBaseContext()) + { + context.Add(item); + + context.SaveChanges(); + } + + return true; } public bool Update(T item) { - throw new NotImplementedException(); + using (var context = new QuickBaseContext()) + { + context.Entry(item); + + context.SaveChanges(); + } + + return true; } public ICollection Get(int id) { - throw new NotImplementedException(); + using (var context = new QuickBaseContext()) + { + return context + .Set() + .Where(r => r.Id == id) + .ToList(); + } } public ICollection Get(Expression> query) { - throw new NotImplementedException(); + using (var context = new QuickBaseContext()) + { + return context + .Set() + .Where(query) + .ToList(); + } } } } diff --git a/COA.EnterpriseServices.DataAccess.EntityFramework/Migrations/20201014010244_initial.Designer.cs b/COA.EnterpriseServices.DataAccess.EntityFramework/Migrations/20201014010244_initial.Designer.cs new file mode 100644 index 0000000..83981b0 --- /dev/null +++ b/COA.EnterpriseServices.DataAccess.EntityFramework/Migrations/20201014010244_initial.Designer.cs @@ -0,0 +1,37 @@ +// +using COA.EnterpriseServices.DataAccess.EntityFramework; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +namespace COA.EnterpriseServices.DataAccess.EntityFramework.Migrations +{ + [DbContext(typeof(QuickBaseContext))] + [Migration("20201014010244_initial")] + partial class initial + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "3.1.9") + .HasAnnotation("Relational:MaxIdentifierLength", 128) + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + modelBuilder.Entity("COA.EnterpriseServices.DataAccess.EntityFramework.Entities.Creditor", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.HasKey("Id"); + + b.ToTable("Creditors"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/COA.EnterpriseServices.DataAccess.EntityFramework/Migrations/20201014010244_initial.cs b/COA.EnterpriseServices.DataAccess.EntityFramework/Migrations/20201014010244_initial.cs new file mode 100644 index 0000000..2dfb3f4 --- /dev/null +++ b/COA.EnterpriseServices.DataAccess.EntityFramework/Migrations/20201014010244_initial.cs @@ -0,0 +1,28 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +namespace COA.EnterpriseServices.DataAccess.EntityFramework.Migrations +{ + public partial class initial : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Creditors", + columns: table => new + { + Id = table.Column(nullable: false) + .Annotation("SqlServer:Identity", "1, 1") + }, + constraints: table => + { + table.PrimaryKey("PK_Creditors", x => x.Id); + }); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Creditors"); + } + } +} diff --git a/COA.EnterpriseServices.DataAccess.EntityFramework/Migrations/QuickBaseContextModelSnapshot.cs b/COA.EnterpriseServices.DataAccess.EntityFramework/Migrations/QuickBaseContextModelSnapshot.cs new file mode 100644 index 0000000..a250ce2 --- /dev/null +++ b/COA.EnterpriseServices.DataAccess.EntityFramework/Migrations/QuickBaseContextModelSnapshot.cs @@ -0,0 +1,35 @@ +// +using COA.EnterpriseServices.DataAccess.EntityFramework; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +namespace COA.EnterpriseServices.DataAccess.EntityFramework.Migrations +{ + [DbContext(typeof(QuickBaseContext))] + partial class QuickBaseContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "3.1.9") + .HasAnnotation("Relational:MaxIdentifierLength", 128) + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + modelBuilder.Entity("COA.EnterpriseServices.DataAccess.EntityFramework.Entities.Creditor", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.HasKey("Id"); + + b.ToTable("Creditors"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/COA.EnterpriseServices.DataAccess.EntityFramework/QuickBaseContext.cs b/COA.EnterpriseServices.DataAccess.EntityFramework/QuickBaseContext.cs index 650ae9f..ddb3218 100644 --- a/COA.EnterpriseServices.DataAccess.EntityFramework/QuickBaseContext.cs +++ b/COA.EnterpriseServices.DataAccess.EntityFramework/QuickBaseContext.cs @@ -8,6 +8,13 @@ namespace COA.EnterpriseServices.DataAccess.EntityFramework { public class QuickBaseContext : DbContext { + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { + optionsBuilder.UseSqlServer("Server=(localdb)\\mssqllocaldb;Database=QuickBase;Trusted_Connection=True;MultipleActiveResultSets=true"); + + base.OnConfiguring(optionsBuilder); + } + public DbSet Creditors { get; set; } } } diff --git a/COA.EnterpriseServices.DataAccess.QuickBase/COA.EnterpriseServices.DataAccess.QuickBase.csproj b/COA.EnterpriseServices.DataAccess.QuickBase/COA.EnterpriseServices.DataAccess.QuickBase.csproj index cb63190..da7db72 100644 --- a/COA.EnterpriseServices.DataAccess.QuickBase/COA.EnterpriseServices.DataAccess.QuickBase.csproj +++ b/COA.EnterpriseServices.DataAccess.QuickBase/COA.EnterpriseServices.DataAccess.QuickBase.csproj @@ -4,4 +4,8 @@ netcoreapp3.1 + + + + diff --git a/COA.EnterpriseServices.DataAccess.QuickBase/Class1.cs b/COA.EnterpriseServices.DataAccess.QuickBase/Class1.cs deleted file mode 100644 index 08f42f6..0000000 --- a/COA.EnterpriseServices.DataAccess.QuickBase/Class1.cs +++ /dev/null @@ -1,8 +0,0 @@ -using System; - -namespace COA.EnterpriseServices.DataAccess.QuickBase -{ - public class Class1 - { - } -} diff --git a/COA.EnterpriseServices.DataAccess.QuickBase/QuickBaseDataAccess.cs b/COA.EnterpriseServices.DataAccess.QuickBase/QuickBaseDataAccess.cs new file mode 100644 index 0000000..f768e29 --- /dev/null +++ b/COA.EnterpriseServices.DataAccess.QuickBase/QuickBaseDataAccess.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Linq.Expressions; + +namespace COA.EnterpriseServices.DataAccess.QuickBase +{ + public class QuickBaseDataAccess : IDataAccess where T : class, IRecord + { + public bool Add(T item) + { + throw new NotImplementedException(); + } + + public bool Update(T item) + { + throw new NotImplementedException(); + } + + public ICollection Get(int id) + { + throw new NotImplementedException(); + } + + public ICollection Get(Expression> query) + { + throw new NotImplementedException(); + } + } +} diff --git a/COA.EnterpriseServices.DataAccess/IDataAccess.cs b/COA.EnterpriseServices.DataAccess/IDataAccess.cs index 7b3142a..2254309 100644 --- a/COA.EnterpriseServices.DataAccess/IDataAccess.cs +++ b/COA.EnterpriseServices.DataAccess/IDataAccess.cs @@ -4,7 +4,7 @@ using System.Linq.Expressions; namespace COA.EnterpriseServices.DataAccess { - public interface IDataAccess where T : IRecord + public interface IDataAccess where T : class, IRecord { bool Add(T item);