File tree

3 files changed

+63
-0
lines changed

3 files changed

+63
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using Microsoft.EntityFrameworkCore;
2+
using Microsoft.EntityFrameworkCore.Design;
3+
using Microsoft.Extensions.Configuration;
4+
using System.IO;
5+
6+
7+
namespace DataAccessLayer
8+
{
9+
public class DesignTimeDbContextFactory :
10+
IDesignTimeDbContextFactory<StoreContext>
11+
{
12+
public StoreContext CreateDbContext(string[] args)
13+
{
14+
IConfigurationRoot configuration = new ConfigurationBuilder()
15+
.SetBasePath(Directory.GetCurrentDirectory())
16+
.AddJsonFile("appsettings.json")
17+
.Build();
18+
var builder = new DbContextOptionsBuilder<StoreContext>();
19+
var connectionString = configuration.GetConnectionString("DefaultConnection");
20+
builder.UseSqlServer(connectionString);
21+
return new StoreContext(builder.Options);
22+
}
23+
}
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
using DataAccessLayer.DataModels;
5+
using Microsoft.EntityFrameworkCore;
6+
7+
namespace DataAccessLayer
8+
{
9+
public class StoreContext : DbContext
10+
{
11+
public StoreContext(DbContextOptions<StoreContext> options) : base(options)
12+
{
13+
14+
}
15+
16+
protected override void OnModelCreating(ModelBuilder modelBuilder)
17+
{
18+
19+
}
20+
21+
#region properties
22+
public DbSet<Category> Categories { get; set; }
23+
public DbSet<Product> Products { get; set; }
24+
#endregion
25+
}
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"ConnectionStrings": {
3+
"DefaultConnection": "Data Source=(localdb)\\ProjectsV13;Initial Catalog=GeeksStore;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False"
4+
},
5+
"exclude": [
6+
"**/bin",
7+
"**/bower_components",
8+
"**/jspm_packages",
9+
"**/node_modules",
10+
"**/obj",
11+
"**/platforms"
12+
]
13+
}

0 commit comments

Comments
 (0)