Skip to content

Commit 3ce7be2

Browse files
authored
Merge pull request #22 from ipvalverde/add-support-efcore-issue-21
Fixes issue #21
2 parents f652aa5 + 073ea14 commit 3ce7be2

26 files changed

Lines changed: 1108 additions & 59 deletions
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>netcoreapp2.2</TargetFramework>
6+
<StartWorkingDirectory>$(MSBuildProjectDirectory)</StartWorkingDirectory>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="EPPlus" Version="4.5.3.2" />
11+
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.2.6" />
12+
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.2.6" />
13+
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.2.6">
14+
<PrivateAssets>all</PrivateAssets>
15+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
16+
</PackageReference>
17+
</ItemGroup>
18+
19+
<ItemGroup>
20+
<Reference Include="EPPlus.DataExtractor">
21+
<HintPath>..\..\src\EPPlus.DataExtractor\bin\Debug\netstandard2.0\EPPlus.DataExtractor.dll</HintPath>
22+
</Reference>
23+
</ItemGroup>
24+
25+
<ItemGroup>
26+
<None Update="Resource\EntityFrameworkSampleData.xlsx">
27+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
28+
</None>
29+
</ItemGroup>
30+
31+
<ItemGroup>
32+
<PackageReference Update="Microsoft.NETCore.App" Version="2.2.6" />
33+
</ItemGroup>
34+
35+
</Project>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.29230.47
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EntityFrameworkCoreSample", "EntityFrameworkCoreSample.csproj", "{CE498BA5-42EC-4277-BFC9-97D4D03242C7}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{CE498BA5-42EC-4277-BFC9-97D4D03242C7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{CE498BA5-42EC-4277-BFC9-97D4D03242C7}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{CE498BA5-42EC-4277-BFC9-97D4D03242C7}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{CE498BA5-42EC-4277-BFC9-97D4D03242C7}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {2B5326D7-2C67-4DEF-8C70-1650044CD433}
24+
EndGlobalSection
25+
EndGlobal

samples/EntityFrameworkCoreSample/Migrations/20191026095633_CreateDatabase.Designer.cs

Lines changed: 64 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
using System;
2+
using Microsoft.EntityFrameworkCore.Migrations;
3+
4+
namespace EntityFrameworkCoreSample.Migrations
5+
{
6+
public partial class CreateDatabase : Migration
7+
{
8+
protected override void Up(MigrationBuilder migrationBuilder)
9+
{
10+
migrationBuilder.CreateTable(
11+
name: "Branches",
12+
columns: table => new
13+
{
14+
Id = table.Column<string>(nullable: false),
15+
Name = table.Column<string>(nullable: true),
16+
Location = table.Column<string>(nullable: true),
17+
Phone = table.Column<string>(nullable: true)
18+
},
19+
constraints: table =>
20+
{
21+
table.PrimaryKey("PK_Branches", x => x.Id);
22+
});
23+
24+
migrationBuilder.CreateTable(
25+
name: "Revenues",
26+
columns: table => new
27+
{
28+
Id = table.Column<Guid>(nullable: false),
29+
Value = table.Column<decimal>(nullable: false),
30+
MonthYear = table.Column<DateTime>(nullable: false),
31+
BranchId = table.Column<string>(nullable: true)
32+
},
33+
constraints: table =>
34+
{
35+
table.PrimaryKey("PK_Revenues", x => x.Id);
36+
table.ForeignKey(
37+
name: "FK_Revenues_Branches_BranchId",
38+
column: x => x.BranchId,
39+
principalTable: "Branches",
40+
principalColumn: "Id",
41+
onDelete: ReferentialAction.Restrict);
42+
});
43+
44+
migrationBuilder.CreateIndex(
45+
name: "IX_Revenues_BranchId",
46+
table: "Revenues",
47+
column: "BranchId");
48+
}
49+
50+
protected override void Down(MigrationBuilder migrationBuilder)
51+
{
52+
migrationBuilder.DropTable(
53+
name: "Revenues");
54+
55+
migrationBuilder.DropTable(
56+
name: "Branches");
57+
}
58+
}
59+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// <auto-generated />
2+
using System;
3+
using EntityFrameworkCoreSample.Model;
4+
using Microsoft.EntityFrameworkCore;
5+
using Microsoft.EntityFrameworkCore.Infrastructure;
6+
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
7+
8+
namespace EntityFrameworkCoreSample.Migrations
9+
{
10+
[DbContext(typeof(VehicleStoreContext))]
11+
partial class VehicleStoreContextModelSnapshot : ModelSnapshot
12+
{
13+
protected override void BuildModel(ModelBuilder modelBuilder)
14+
{
15+
#pragma warning disable 612, 618
16+
modelBuilder
17+
.HasAnnotation("ProductVersion", "2.2.6-servicing-10079");
18+
19+
modelBuilder.Entity("EntityFrameworkCoreSample.Model.BranchEntity", b =>
20+
{
21+
b.Property<string>("Id")
22+
.ValueGeneratedOnAdd();
23+
24+
b.Property<string>("Location");
25+
26+
b.Property<string>("Name");
27+
28+
b.Property<string>("Phone");
29+
30+
b.HasKey("Id");
31+
32+
b.ToTable("Branches");
33+
});
34+
35+
modelBuilder.Entity("EntityFrameworkCoreSample.Model.MonthlyRevenueEntity", b =>
36+
{
37+
b.Property<Guid>("Id")
38+
.ValueGeneratedOnAdd();
39+
40+
b.Property<string>("BranchId");
41+
42+
b.Property<DateTime>("MonthYear");
43+
44+
b.Property<decimal>("Value");
45+
46+
b.HasKey("Id");
47+
48+
b.HasIndex("BranchId");
49+
50+
b.ToTable("Revenues");
51+
});
52+
53+
modelBuilder.Entity("EntityFrameworkCoreSample.Model.MonthlyRevenueEntity", b =>
54+
{
55+
b.HasOne("EntityFrameworkCoreSample.Model.BranchEntity", "Branch")
56+
.WithMany("Revenues")
57+
.HasForeignKey("BranchId");
58+
});
59+
#pragma warning restore 612, 618
60+
}
61+
}
62+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using System.Collections.Generic;
2+
using System.Linq;
3+
using System.Text;
4+
5+
namespace EntityFrameworkCoreSample.Model
6+
{
7+
public class BranchEntity
8+
{
9+
public static string TableName => "Branches";
10+
11+
public string Id { get; set; }
12+
13+
public string Name { get; set; }
14+
15+
public string Location { get; set; }
16+
17+
public string Phone { get; set; }
18+
19+
public ICollection<MonthlyRevenueEntity> Revenues { get; set; }
20+
21+
public BranchEntity()
22+
{
23+
this.Revenues = new HashSet<MonthlyRevenueEntity>();
24+
}
25+
26+
public override string ToString()
27+
{
28+
var vehiclesStringBuilder = Revenues
29+
.Select((v, index) => new
30+
{
31+
Index = index,
32+
VehicleStr = v.ToString(),
33+
})
34+
.Aggregate(
35+
new StringBuilder(),
36+
(ac, cu) => ac.AppendLine($"Revenues[{cu.Index}]={cu}"));
37+
38+
return $@"{nameof(BranchEntity)}
39+
Id={Id}
40+
Name={Name}
41+
Location={Location}
42+
Phone={Phone}
43+
{vehiclesStringBuilder.ToString()}
44+
45+
----------------------------------------";
46+
}
47+
}
48+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System;
2+
3+
namespace EntityFrameworkCoreSample.Model
4+
{
5+
public class MonthlyRevenueEntity
6+
{
7+
public static string TableName => "Revenues";
8+
9+
public Guid Id { get; set; }
10+
11+
public decimal Value { get; set; }
12+
13+
public DateTime MonthYear { get; set; }
14+
15+
public string BranchId { get; set; }
16+
public BranchEntity Branch { get; set; }
17+
18+
public override string ToString() =>
19+
$"Id={Id}, BranchId={BranchId}, MonthYear={MonthYear.ToString("Y")}, Value={Value}";
20+
}
21+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using Microsoft.EntityFrameworkCore;
2+
3+
namespace EntityFrameworkCoreSample.Model
4+
{
5+
public class VehicleStoreContext : DbContext
6+
{
7+
public DbSet<BranchEntity> Branches { get; set; }
8+
9+
public DbSet<MonthlyRevenueEntity> Revenues { get; set; }
10+
11+
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
12+
{
13+
optionsBuilder.UseSqlite("Data Source=vehicle_store.db");
14+
}
15+
16+
protected override void OnModelCreating(ModelBuilder modelBuilder)
17+
{
18+
modelBuilder.Entity<BranchEntity>()
19+
.ToTable(BranchEntity.TableName)
20+
.HasMany(b => b.Revenues)
21+
.WithOne(r => r.Branch);
22+
23+
modelBuilder.Entity<MonthlyRevenueEntity>()
24+
.ToTable(MonthlyRevenueEntity.TableName);
25+
}
26+
}
27+
}

0 commit comments

Comments
 (0)