Skip to content

Commit f0b79e9

Browse files
committed
Adds a Data layer project with an initial EF model
1 parent ff6ca2d commit f0b79e9

File tree

7 files changed

+176
-1
lines changed

7 files changed

+176
-1
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using DataLayer.Entities;
2+
using Microsoft.EntityFrameworkCore;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Text;
6+
7+
namespace DataLayer
8+
{
9+
public class ApplicationDbContext : DbContext
10+
{
11+
public DbSet<Entity> Entities { get; set; }
12+
13+
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options)
14+
{
15+
}
16+
17+
public ApplicationDbContext(DbContextOptions options) : base(options)
18+
{
19+
}
20+
21+
public ApplicationDbContext() : base()
22+
{
23+
}
24+
25+
protected override void OnConfiguring(DbContextOptionsBuilder options) => options.UseSqlServer("Server=(localdb)\\mssqllocaldb;Database=mydb;Trusted_Connection=True;MultipleActiveResultSets=True");
26+
}
27+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netcoreapp3.1</TargetFramework>
5+
<!--<SkipFunctionsDepsCopy>true</SkipFunctionsDepsCopy>-->
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.9" />
10+
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.9" />
11+
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.9" />
12+
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.9" />
13+
</ItemGroup>
14+
15+
</Project>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.ComponentModel.DataAnnotations;
4+
using System.Text;
5+
6+
namespace DataLayer.Entities
7+
{
8+
public class Entity
9+
{
10+
[Key]
11+
public int Id { get; set; }
12+
13+
public string Name { get; set; }
14+
15+
public string Description { get; set; }
16+
}
17+
}

projects/azure-functions/DbContextExample/Data/Migrations/20201020183453_Initial.Designer.cs

Lines changed: 43 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using Microsoft.EntityFrameworkCore.Migrations;
2+
3+
namespace DataLayer.Migrations
4+
{
5+
public partial class Initial : Migration
6+
{
7+
protected override void Up(MigrationBuilder migrationBuilder)
8+
{
9+
migrationBuilder.CreateTable(
10+
name: "Entities",
11+
columns: table => new
12+
{
13+
Id = table.Column<int>(nullable: false)
14+
.Annotation("SqlServer:Identity", "1, 1"),
15+
Name = table.Column<string>(nullable: true),
16+
Description = table.Column<string>(nullable: true)
17+
},
18+
constraints: table =>
19+
{
20+
table.PrimaryKey("PK_Entities", x => x.Id);
21+
});
22+
}
23+
24+
protected override void Down(MigrationBuilder migrationBuilder)
25+
{
26+
migrationBuilder.DropTable(
27+
name: "Entities");
28+
}
29+
}
30+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// <auto-generated />
2+
using DataLayer;
3+
using Microsoft.EntityFrameworkCore;
4+
using Microsoft.EntityFrameworkCore.Infrastructure;
5+
using Microsoft.EntityFrameworkCore.Metadata;
6+
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
7+
8+
namespace DataLayer.Migrations
9+
{
10+
[DbContext(typeof(ApplicationDbContext))]
11+
partial class ApplicationDbContextModelSnapshot : ModelSnapshot
12+
{
13+
protected override void BuildModel(ModelBuilder modelBuilder)
14+
{
15+
#pragma warning disable 612, 618
16+
modelBuilder
17+
.HasAnnotation("ProductVersion", "3.1.0")
18+
.HasAnnotation("Relational:MaxIdentifierLength", 128)
19+
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
20+
21+
modelBuilder.Entity("DataLayer.Entities.Entity", b =>
22+
{
23+
b.Property<int>("Id")
24+
.ValueGeneratedOnAdd()
25+
.HasColumnType("int")
26+
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
27+
28+
b.Property<string>("Description")
29+
.HasColumnType("nvarchar(max)");
30+
31+
b.Property<string>("Name")
32+
.HasColumnType("nvarchar(max)");
33+
34+
b.HasKey("Id");
35+
36+
b.ToTable("Entities");
37+
});
38+
#pragma warning restore 612, 618
39+
}
40+
}
41+
}

projects/azure-functions/DbContextExample/DbContextExample.sln

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio Version 16
44
VisualStudioVersion = 16.0.30309.148
55
MinimumVisualStudioVersion = 10.0.40219.1
6-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Function", "Function\Function.csproj", "{E8020AA9-4E33-4049-8B8A-0B4965AEA3F6}"
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DataLayer", "Data\DataLayer.csproj", "{30BD593E-8752-4661-9FCB-E97AD112ED4C}"
7+
EndProject
8+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Function", "Function\Function.csproj", "{E8020AA9-4E33-4049-8B8A-0B4965AEA3F6}"
79
EndProject
810
Global
911
GlobalSection(SolutionConfigurationPlatforms) = preSolution

0 commit comments

Comments
 (0)