Skip to content

Commit fc08b90

Browse files
authored
Apply EF Core compiled model #20 (#21)
1 parent be23567 commit fc08b90

28 files changed

+1003
-20
lines changed

.gitattributes

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,70 @@
1+
###############################################################################
2+
# Set default behavior to automatically normalize line endings.
3+
###############################################################################
14
* text=auto
2-
*.razor linguist-language=C#
5+
*.sh text eol=lf
6+
7+
###############################################################################
8+
# Set default behavior for command prompt diff.
9+
#
10+
# This is need for earlier builds of msysgit that does not have it on by
11+
# default for csharp files.
12+
# Note: This is only used by command line
13+
###############################################################################
14+
#*.cs diff=csharp
15+
16+
###############################################################################
17+
# Set the merge driver for project and solution files
18+
#
19+
# Merging from the command prompt will add diff markers to the files if there
20+
# are conflicts (Merging from VS is not affected by the settings below, in VS
21+
# the diff markers are never inserted). Diff markers may cause the following
22+
# file extensions to fail to load in VS. An alternative would be to treat
23+
# these files as binary and thus will always conflict and require user
24+
# intervention with every merge. To do so, just uncomment the entries below
25+
###############################################################################
26+
#*.sln merge=binary
27+
#*.csproj merge=binary
28+
#*.vbproj merge=binary
29+
#*.vcxproj merge=binary
30+
#*.vcproj merge=binary
31+
#*.dbproj merge=binary
32+
#*.fsproj merge=binary
33+
#*.lsproj merge=binary
34+
#*.wixproj merge=binary
35+
#*.modelproj merge=binary
36+
#*.sqlproj merge=binary
37+
#*.wwaproj merge=binary
38+
39+
###############################################################################
40+
# behavior for image files
41+
#
42+
# image files are treated as binary by default.
43+
###############################################################################
44+
#*.jpg binary
45+
#*.png binary
46+
#*.gif binary
47+
48+
###############################################################################
49+
# diff behavior for common document formats
50+
#
51+
# Convert binary document formats to text before diffing them. This feature
52+
# is only available from the command line. Turn it on by uncommenting the
53+
# entries below.
54+
###############################################################################
55+
#*.doc diff=astextplain
56+
#*.DOC diff=astextplain
57+
#*.docx diff=astextplain
58+
#*.DOCX diff=astextplain
59+
#*.dot diff=astextplain
60+
#*.DOT diff=astextplain
61+
#*.pdf diff=astextplain
62+
#*.PDF diff=astextplain
63+
#*.rtf diff=astextplain
64+
#*.RTF diff=astextplain
65+
66+
67+
###############################################################################
68+
# Certificates are binary
69+
###############################################################################
70+
*.pfx binary

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,14 @@ Reference to https://github.com/Sairyss/domain-driven-hexagon
4848
- [.NET SDK](https://dotnet.microsoft.com/download/dotnet/6.0): 6.0.100-preview.5.21271.2
4949
- [nodejs](https://nodejs.org/en/download): v15.5.1
5050
- [tye](https://github.com/dotnet/tye): 0.8.0-alpha.21301.1+0fed0b38e730cd07caf0a90287090638c110b77d
51+
- [Tan Hoang](https://github.com/cuno92) and [Mohammad AlQuraian](https://github.com/Quraian) have confused about `tye 0.8.0`, and asked to add the guidance so I put it here
52+
- Follow the guidance at https://github.com/dotnet/tye/blob/647a608892/docs/getting_started.md#working-with-ci-builds
53+
- More specifically, adding `dotnet tool install -g Microsoft.Tye --version "0.8.0-*" --add-source https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet5/nuget/v3/index.json` to your terminal
5154
- [dapr](https://dapr.io/): 1.2.0
5255
- Dev tools:
5356
- [vscode tye](https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-tye) extension
5457
- [vscode REST Client](https://marketplace.visualstudio.com/items?itemName=humao.rest-client) extension
58+
- [vscode Markmap](https://marketplace.visualstudio.com/items?itemName=gera2ld.markmap-vscode) extension
5559

5660
# :hearts: Technical stacks
5761
- ✔️ **[`.NET Core 6`](https://dotnet.microsoft.com/download)** - .NET Framework and .NET Core, including ASP.NET and ASP.NET Core
@@ -278,7 +282,7 @@ $ tye run
278282
<tbody>
279283
<tr>
280284
<td>1</td>
281-
<td>gateway</td>
285+
<td>YARP Gateway (downstream)</td>
282286
<td><a href="http://localhost:5000">http://localhost:5000</a></td>
283287
</tr>
284288
<tr>
@@ -306,6 +310,11 @@ $ tye run
306310
<td>setting (upstream service)</td>
307311
<td><a href="http://localhost:5005">http://localhost:5005</a></td>
308312
</tr>
313+
<tr>
314+
<td colspan="3">
315+
<img src="assets/highlevel_components.png">
316+
</td>
317+
</tr>
309318
</tbody>
310319
</table>
311320

assets/highlevel_components.png

74.2 KB
Loading
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
// <auto-generated />
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Reflection;
5+
using CustomerService.AppCore.Core.Entities;
6+
using Microsoft.EntityFrameworkCore;
7+
using Microsoft.EntityFrameworkCore.Metadata;
8+
using N8T.Core.Domain;
9+
10+
#pragma warning disable 219, 612, 618
11+
#nullable enable
12+
13+
namespace CustomerService.Infrastructure
14+
{
15+
partial class CreditCardEntityType
16+
{
17+
public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType? baseEntityType = null)
18+
{
19+
var runtimeEntityType = model.AddEntityType(
20+
"CustomerService.AppCore.Core.Entities.CreditCard",
21+
typeof(CreditCard),
22+
baseEntityType);
23+
24+
var id = runtimeEntityType.AddProperty(
25+
"Id",
26+
typeof(Guid),
27+
propertyInfo: typeof(EntityBase).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly),
28+
fieldInfo: typeof(EntityBase).GetField("<Id>k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly),
29+
valueGenerated: ValueGenerated.OnAdd,
30+
afterSaveBehavior: PropertySaveBehavior.Throw);
31+
id.AddAnnotation("Relational:ColumnName", "id");
32+
id.AddAnnotation("Relational:ColumnType", "uuid");
33+
id.AddAnnotation("Relational:DefaultValueSql", "uuid_generate_v4()");
34+
35+
var active = runtimeEntityType.AddProperty(
36+
"Active",
37+
typeof(bool),
38+
propertyInfo: typeof(CreditCard).GetProperty("Active", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly),
39+
fieldInfo: typeof(CreditCard).GetField("<Active>k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly));
40+
active.AddAnnotation("Relational:ColumnName", "active");
41+
42+
var cardNumber = runtimeEntityType.AddProperty(
43+
"CardNumber",
44+
typeof(string),
45+
propertyInfo: typeof(CreditCard).GetProperty("CardNumber", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly),
46+
fieldInfo: typeof(CreditCard).GetField("<CardNumber>k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly),
47+
maxLength: 16);
48+
cardNumber.AddAnnotation("Relational:ColumnName", "card_number");
49+
50+
var created = runtimeEntityType.AddProperty(
51+
"Created",
52+
typeof(DateTime),
53+
propertyInfo: typeof(EntityBase).GetProperty("Created", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly),
54+
fieldInfo: typeof(EntityBase).GetField("<Created>k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly),
55+
valueGenerated: ValueGenerated.OnAdd);
56+
created.AddAnnotation("Relational:ColumnName", "created");
57+
created.AddAnnotation("Relational:DefaultValueSql", "now()");
58+
59+
var customerId = runtimeEntityType.AddProperty(
60+
"CustomerId",
61+
typeof(Guid));
62+
customerId.AddAnnotation("Relational:ColumnName", "customer_id");
63+
64+
var expiry = runtimeEntityType.AddProperty(
65+
"Expiry",
66+
typeof(DateTime),
67+
propertyInfo: typeof(CreditCard).GetProperty("Expiry", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly),
68+
fieldInfo: typeof(CreditCard).GetField("<Expiry>k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly));
69+
expiry.AddAnnotation("Relational:ColumnName", "expiry");
70+
71+
var nameOnCard = runtimeEntityType.AddProperty(
72+
"NameOnCard",
73+
typeof(string),
74+
propertyInfo: typeof(CreditCard).GetProperty("NameOnCard", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly),
75+
fieldInfo: typeof(CreditCard).GetField("<NameOnCard>k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly),
76+
maxLength: 20);
77+
nameOnCard.AddAnnotation("Relational:ColumnName", "name_on_card");
78+
79+
var updated = runtimeEntityType.AddProperty(
80+
"Updated",
81+
typeof(DateTime?),
82+
propertyInfo: typeof(EntityBase).GetProperty("Updated", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly),
83+
fieldInfo: typeof(EntityBase).GetField("<Updated>k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly),
84+
nullable: true);
85+
updated.AddAnnotation("Relational:ColumnName", "updated");
86+
87+
var key = runtimeEntityType.AddKey(
88+
new[] { id });
89+
runtimeEntityType.SetPrimaryKey(key);
90+
key.AddAnnotation("Relational:Name", "pk_credit_cards");
91+
92+
var index = runtimeEntityType.AddIndex(
93+
new[] { customerId });
94+
index.AddAnnotation("Relational:Name", "ix_credit_cards_customer_id");
95+
96+
var index0 = runtimeEntityType.AddIndex(
97+
new[] { id },
98+
unique: true);
99+
index0.AddAnnotation("Relational:Name", "ix_credit_cards_id");
100+
101+
return runtimeEntityType;
102+
}
103+
104+
public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType)
105+
{
106+
var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("CustomerId")! },
107+
principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id")! })!,
108+
principalEntityType,
109+
deleteBehavior: DeleteBehavior.Cascade,
110+
required: true);
111+
112+
var customer = declaringEntityType.AddNavigation("Customer",
113+
runtimeForeignKey,
114+
onDependent: true,
115+
typeof(Customer),
116+
propertyInfo: typeof(CreditCard).GetProperty("Customer", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly),
117+
fieldInfo: typeof(CreditCard).GetField("<Customer>k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly));
118+
119+
var creditCards = principalEntityType.AddNavigation("CreditCards",
120+
runtimeForeignKey,
121+
onDependent: false,
122+
typeof(IEnumerable<CreditCard>),
123+
propertyInfo: typeof(Customer).GetProperty("CreditCards", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly),
124+
fieldInfo: typeof(Customer).GetField("_creditCards", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly));
125+
126+
runtimeForeignKey.AddAnnotation("Relational:Name", "fk_credit_cards_customers_customer_id");
127+
return runtimeForeignKey;
128+
}
129+
130+
public static void CreateAnnotations(RuntimeEntityType runtimeEntityType)
131+
{
132+
runtimeEntityType.AddAnnotation("Relational:FunctionName", null);
133+
runtimeEntityType.AddAnnotation("Relational:Schema", "customer");
134+
runtimeEntityType.AddAnnotation("Relational:SqlQuery", null);
135+
runtimeEntityType.AddAnnotation("Relational:TableName", "credit_cards");
136+
runtimeEntityType.AddAnnotation("Relational:ViewName", null);
137+
runtimeEntityType.AddAnnotation("Relational:ViewSchema", null);
138+
139+
Customize(runtimeEntityType);
140+
}
141+
142+
static partial void Customize(RuntimeEntityType runtimeEntityType);
143+
}
144+
}
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
// <auto-generated />
2+
using System;
3+
using System.Reflection;
4+
using CustomerService.AppCore.Core.Entities;
5+
using Microsoft.EntityFrameworkCore.Metadata;
6+
using N8T.Core.Domain;
7+
8+
#pragma warning disable 219, 612, 618
9+
#nullable enable
10+
11+
namespace CustomerService.Infrastructure
12+
{
13+
partial class CustomerEntityType
14+
{
15+
public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType? baseEntityType = null)
16+
{
17+
var runtimeEntityType = model.AddEntityType(
18+
"CustomerService.AppCore.Core.Entities.Customer",
19+
typeof(Customer),
20+
baseEntityType);
21+
22+
var id = runtimeEntityType.AddProperty(
23+
"Id",
24+
typeof(Guid),
25+
propertyInfo: typeof(EntityBase).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly),
26+
fieldInfo: typeof(EntityBase).GetField("<Id>k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly),
27+
valueGenerated: ValueGenerated.OnAdd,
28+
afterSaveBehavior: PropertySaveBehavior.Throw);
29+
id.AddAnnotation("Relational:ColumnName", "id");
30+
id.AddAnnotation("Relational:ColumnType", "uuid");
31+
id.AddAnnotation("Relational:DefaultValueSql", "uuid_generate_v4()");
32+
33+
var balance = runtimeEntityType.AddProperty(
34+
"Balance",
35+
typeof(decimal),
36+
propertyInfo: typeof(Customer).GetProperty("Balance", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly),
37+
fieldInfo: typeof(Customer).GetField("<Balance>k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly));
38+
balance.AddAnnotation("Relational:ColumnName", "balance");
39+
40+
var countryId = runtimeEntityType.AddProperty(
41+
"CountryId",
42+
typeof(Guid),
43+
propertyInfo: typeof(Customer).GetProperty("CountryId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly),
44+
fieldInfo: typeof(Customer).GetField("<CountryId>k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly));
45+
countryId.AddAnnotation("Relational:ColumnName", "country_id");
46+
countryId.AddAnnotation("Relational:ColumnType", "uuid");
47+
48+
var created = runtimeEntityType.AddProperty(
49+
"Created",
50+
typeof(DateTime),
51+
propertyInfo: typeof(EntityBase).GetProperty("Created", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly),
52+
fieldInfo: typeof(EntityBase).GetField("<Created>k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly),
53+
valueGenerated: ValueGenerated.OnAdd);
54+
created.AddAnnotation("Relational:ColumnName", "created");
55+
created.AddAnnotation("Relational:DefaultValueSql", "now()");
56+
57+
var email = runtimeEntityType.AddProperty(
58+
"Email",
59+
typeof(string),
60+
propertyInfo: typeof(Customer).GetProperty("Email", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly),
61+
fieldInfo: typeof(Customer).GetField("<Email>k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly));
62+
email.AddAnnotation("Relational:ColumnName", "email");
63+
64+
var firstName = runtimeEntityType.AddProperty(
65+
"FirstName",
66+
typeof(string),
67+
propertyInfo: typeof(Customer).GetProperty("FirstName", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly),
68+
fieldInfo: typeof(Customer).GetField("<FirstName>k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly));
69+
firstName.AddAnnotation("Relational:ColumnName", "first_name");
70+
71+
var lastName = runtimeEntityType.AddProperty(
72+
"LastName",
73+
typeof(string),
74+
propertyInfo: typeof(Customer).GetProperty("LastName", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly),
75+
fieldInfo: typeof(Customer).GetField("<LastName>k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly));
76+
lastName.AddAnnotation("Relational:ColumnName", "last_name");
77+
78+
var updated = runtimeEntityType.AddProperty(
79+
"Updated",
80+
typeof(DateTime?),
81+
propertyInfo: typeof(EntityBase).GetProperty("Updated", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly),
82+
fieldInfo: typeof(EntityBase).GetField("<Updated>k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly),
83+
nullable: true);
84+
updated.AddAnnotation("Relational:ColumnName", "updated");
85+
86+
var key = runtimeEntityType.AddKey(
87+
new[] { id });
88+
runtimeEntityType.SetPrimaryKey(key);
89+
key.AddAnnotation("Relational:Name", "pk_customers");
90+
91+
var index = runtimeEntityType.AddIndex(
92+
new[] { id },
93+
unique: true);
94+
index.AddAnnotation("Relational:Name", "ix_customers_id");
95+
96+
return runtimeEntityType;
97+
}
98+
99+
public static void CreateAnnotations(RuntimeEntityType runtimeEntityType)
100+
{
101+
runtimeEntityType.AddAnnotation("Relational:FunctionName", null);
102+
runtimeEntityType.AddAnnotation("Relational:Schema", "customer");
103+
runtimeEntityType.AddAnnotation("Relational:SqlQuery", null);
104+
runtimeEntityType.AddAnnotation("Relational:TableName", "customers");
105+
runtimeEntityType.AddAnnotation("Relational:ViewName", null);
106+
runtimeEntityType.AddAnnotation("Relational:ViewSchema", null);
107+
108+
Customize(runtimeEntityType);
109+
}
110+
111+
static partial void Customize(RuntimeEntityType runtimeEntityType);
112+
}
113+
}

0 commit comments

Comments
 (0)