Skip to content

Commit 350b615

Browse files
committed
Implemented EF Core and added first migration
1 parent 0404fe3 commit 350b615

File tree

11 files changed

+198
-6
lines changed

11 files changed

+198
-6
lines changed

src/AbpCompanyName.AbpProjectName.Application/AbpProjectNameApplicationModule.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44

55
namespace AbpCompanyName.AbpProjectName
66
{
7-
[DependsOn(typeof(AbpProjectNameCoreModule), typeof(AbpAutoMapperModule))]
7+
[DependsOn(
8+
typeof(AbpProjectNameCoreModule),
9+
typeof(AbpAutoMapperModule))]
810
public class AbpProjectNameApplicationModule : AbpModule
911
{
1012
public override void Initialize()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using Microsoft.EntityFrameworkCore;
2+
using Microsoft.EntityFrameworkCore.Infrastructure;
3+
4+
namespace AbpCompanyName.AbpProjectName.EntityFrameworkCore
5+
{
6+
public class AbpProjectNameDbContextFactory : IDbContextFactory<AbpProjectNameDbContext>
7+
{
8+
public AbpProjectNameDbContext Create()
9+
{
10+
var builder = new DbContextOptionsBuilder<AbpProjectNameDbContext>();
11+
builder.UseSqlServer("Server=localhost; Database=AbpProjectNameDb; Trusted_Connection=True;");
12+
return new AbpProjectNameDbContext(builder.Options);
13+
}
14+
}
15+
}

src/AbpCompanyName.AbpProjectName.EntityFrameworkCore/EntityFrameworkCore/AbpProjectNameEntityFrameworkCoreModule.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44

55
namespace AbpCompanyName.AbpProjectName.EntityFrameworkCore
66
{
7-
[DependsOn(typeof(AbpProjectNameCoreModule), typeof(AbpEntityFrameworkCoreModule))]
7+
[DependsOn(
8+
typeof(AbpProjectNameCoreModule),
9+
typeof(AbpEntityFrameworkCoreModule))]
810
public class AbpProjectNameEntityFrameworkCoreModule : AbpModule
911
{
1012
public override void PreInitialize()

src/AbpCompanyName.AbpProjectName.EntityFrameworkCore/Migrations/20160619114439_Initial_Migration_Added_Product.Designer.cs

Lines changed: 45 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using Microsoft.EntityFrameworkCore.Migrations;
4+
using Microsoft.EntityFrameworkCore.Metadata;
5+
6+
namespace AbpCompanyName.AbpProjectName.EntityFrameworkCore.Migrations
7+
{
8+
public partial class Initial_Migration_Added_Product : Migration
9+
{
10+
protected override void Up(MigrationBuilder migrationBuilder)
11+
{
12+
migrationBuilder.CreateTable(
13+
name: "Products",
14+
columns: table => new
15+
{
16+
Id = table.Column<int>(nullable: false)
17+
.Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
18+
CreationTime = table.Column<DateTime>(nullable: false),
19+
CreatorUserId = table.Column<long>(nullable: true),
20+
LastModificationTime = table.Column<DateTime>(nullable: true),
21+
LastModifierUserId = table.Column<long>(nullable: true),
22+
Name = table.Column<string>(nullable: false),
23+
Price = table.Column<float>(nullable: true)
24+
},
25+
constraints: table =>
26+
{
27+
table.PrimaryKey("PK_Products", x => x.Id);
28+
});
29+
}
30+
31+
protected override void Down(MigrationBuilder migrationBuilder)
32+
{
33+
migrationBuilder.DropTable(
34+
name: "Products");
35+
}
36+
}
37+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using System;
2+
using Microsoft.EntityFrameworkCore;
3+
using Microsoft.EntityFrameworkCore.Infrastructure;
4+
using Microsoft.EntityFrameworkCore.Metadata;
5+
using Microsoft.EntityFrameworkCore.Migrations;
6+
using AbpCompanyName.AbpProjectName.EntityFrameworkCore;
7+
8+
namespace AbpCompanyName.AbpProjectName.EntityFrameworkCore.Migrations
9+
{
10+
[DbContext(typeof(AbpProjectNameDbContext))]
11+
partial class AbpProjectNameDbContextModelSnapshot : ModelSnapshot
12+
{
13+
protected override void BuildModel(ModelBuilder modelBuilder)
14+
{
15+
modelBuilder
16+
.HasAnnotation("ProductVersion", "1.0.0-rc2-20901")
17+
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
18+
19+
modelBuilder.Entity("AbpCompanyName.AbpProjectName.Products.Product", b =>
20+
{
21+
b.Property<int>("Id")
22+
.ValueGeneratedOnAdd();
23+
24+
b.Property<DateTime>("CreationTime");
25+
26+
b.Property<long?>("CreatorUserId");
27+
28+
b.Property<DateTime?>("LastModificationTime");
29+
30+
b.Property<long?>("LastModifierUserId");
31+
32+
b.Property<string>("Name")
33+
.IsRequired()
34+
.HasAnnotation("MaxLength", 128);
35+
36+
b.Property<float?>("Price");
37+
38+
b.HasKey("Id");
39+
40+
b.ToTable("Products");
41+
});
42+
}
43+
}
44+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
namespace AbpCompanyName.AbpProjectName
2+
{
3+
/* WORKAROUND
4+
* This is needed since .NET CLI does not support class library projects!
5+
* See https://docs.efproject.net/en/latest/cli/dotnet.html#preview-1-known-issues
6+
*/
7+
public class Program
8+
{
9+
public static void Main()
10+
{
11+
12+
}
13+
}
14+
}

src/AbpCompanyName.AbpProjectName.EntityFrameworkCore/project.json

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,32 @@
33

44
"dependencies": {
55
"Abp.EntityFrameworkCore": "0.9.4",
6-
"AbpCompanyName.AbpProjectName.Core": "1.0.0.0-*"
6+
"AbpCompanyName.AbpProjectName.Core": "1.0.0.0-*",
7+
"Microsoft.EntityFrameworkCore.SqlServer": "1.0.0-rc2-final",
8+
"Microsoft.EntityFrameworkCore.Tools": {
9+
"version": "1.0.0-preview1-final",
10+
"type": "build"
11+
}
12+
},
13+
14+
"tools": {
15+
"Microsoft.EntityFrameworkCore.Tools": {
16+
"version": "1.0.0-preview1-final",
17+
"imports": [
18+
"portable-net45+win8+dnxcore50",
19+
"portable-net45+win8"
20+
]
21+
}
22+
},
23+
24+
"buildOptions": {
25+
"emitEntryPoint": true
726
},
827

928
"frameworks": {
1029
"net452": {
30+
"imports": "portable-net451+win8",
31+
"Microsoft.NETCore.App": "1.0.0-rc2-3002702"
1132
}
1233
}
1334
}

src/AbpCompanyName.AbpProjectName.Web/AbpProjectNameWebModule.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
using System.Reflection;
22
using Abp.AspNetCore;
33
using Abp.Modules;
4+
using AbpCompanyName.AbpProjectName.EntityFrameworkCore;
45

56
namespace AbpCompanyName.AbpProjectName.Web
67
{
7-
[DependsOn(typeof(AbpProjectNameApplicationModule), typeof(AbpAspNetCoreModule))]
8+
[DependsOn(
9+
typeof(AbpProjectNameApplicationModule),
10+
typeof(AbpProjectNameEntityFrameworkCoreModule),
11+
typeof(AbpAspNetCoreModule))]
812
public class AbpProjectNameWebModule : AbpModule
913
{
1014
public override void PreInitialize()

src/AbpCompanyName.AbpProjectName.Web/Controllers/HomeController.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.Threading.Tasks;
12
using Abp.AspNetCore.Mvc.Controllers;
23
using AbpCompanyName.AbpProjectName.Products;
34
using Microsoft.AspNetCore.Mvc;
@@ -13,9 +14,9 @@ public HomeController(IProductAppService productAppService)
1314
_productAppService = productAppService;
1415
}
1516

16-
public IActionResult Index()
17+
public async Task<IActionResult> Index()
1718
{
18-
var model = _productAppService.GetAllProducts();
19+
var model = await _productAppService.GetAllProducts();
1920
return View(model);
2021
}
2122
}

0 commit comments

Comments
 (0)