added core classes

This commit is contained in:
Ryan Peters 2020-10-13 21:24:27 -04:00
parent 3c6e421dbf
commit e919026502
9 changed files with 173 additions and 14 deletions

View File

@ -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<T> : IDataAccess<T> where T : IRecord
public class EntityDataAccess<T> : IDataAccess<T> 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<T> Get(int id)
{
throw new NotImplementedException();
using (var context = new QuickBaseContext())
{
return context
.Set<T>()
.Where(r => r.Id == id)
.ToList();
}
}
public ICollection<T> Get(Expression<Func<T, bool>> query)
{
throw new NotImplementedException();
using (var context = new QuickBaseContext())
{
return context
.Set<T>()
.Where(query)
.ToList();
}
}
}
}

View File

@ -0,0 +1,37 @@
// <auto-generated />
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<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
b.HasKey("Id");
b.ToTable("Creditors");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -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<int>(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");
}
}
}

View File

@ -0,0 +1,35 @@
// <auto-generated />
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<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
b.HasKey("Id");
b.ToTable("Creditors");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -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<Creditor> Creditors { get; set; }
}
}

View File

@ -4,4 +4,8 @@
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\COA.EnterpriseServices.DataAccess\COA.EnterpriseServices.DataAccess.csproj" />
</ItemGroup>
</Project>

View File

@ -1,8 +0,0 @@
using System;
namespace COA.EnterpriseServices.DataAccess.QuickBase
{
public class Class1
{
}
}

View File

@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
namespace COA.EnterpriseServices.DataAccess.QuickBase
{
public class QuickBaseDataAccess<T> : IDataAccess<T> where T : class, IRecord
{
public bool Add(T item)
{
throw new NotImplementedException();
}
public bool Update(T item)
{
throw new NotImplementedException();
}
public ICollection<T> Get(int id)
{
throw new NotImplementedException();
}
public ICollection<T> Get(Expression<Func<T, bool>> query)
{
throw new NotImplementedException();
}
}
}

View File

@ -4,7 +4,7 @@ using System.Linq.Expressions;
namespace COA.EnterpriseServices.DataAccess
{
public interface IDataAccess<T> where T : IRecord
public interface IDataAccess<T> where T : class, IRecord
{
bool Add(T item);