You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+44-7Lines changed: 44 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,13 +1,31 @@
1
-
##Trackable Entities Core Sample
1
+
# Trackable Entities for EF Core Sample
2
2
3
-
Sample solution using Trackable Entities with .NET Core.
3
+
Sample solution using Trackable Entities with ASP.NET Core and Entity Framework Core.
4
+
5
+
## Steps
6
+
7
+
> **Note**: Perform the following steps to create an end-to-end solution using [Trackable Entities](http://trackableentities.github.io/) with a REST-ful [ASP.NET Core](https://docs.microsoft.com/en-us/aspnet/core/) web api service and a client .NET console application. To see the final outcome of this process, please refer to the code in this repository.
8
+
9
+
1. Create the NorthwindSlim sample database.
10
+
2. Generate _server-side_ trackable entities.
11
+
3. Link to generated entities from a NetStandard project.
12
+
4. Add an ASP.NET Core web api project and use EF Core Migrations to create a _new database_ from the generated entities.
13
+
5. Install the **TrackableEntities.EF.Core** NuGet package and add web api controllers with GET, POST, PUT and DELETE actions.
14
+
6. Generate _client-side_ trackable entities in a traditional class library project.
15
+
7. Add a traditional .NET client console application that uses the **TrackableEntities.Client** NuGet package to perform client-side change tracking, sending object graphs of changed entities to the Web API service where they are saved to the database in a single transaction.
4
16
5
17
## NorthwindSlim Database
6
18
19
+
_This sample shows how you can **both** generate entities from an existing database (database-first) and create a new database from existing entities (code-first). In real life you would do either one or the other._
20
+
7
21
- This sample uses a skinny version of the Northwind sample database, called _NorthwindSlim_, which you can download from http://bit.ly/northwindslim.
8
22
- Open SQL Server Management Studio, connect to (localdb)\MsSqlLocalDb and create a new database named _NorthwindSlim_. Then run the NorthwindSlim.sql file, which will create all the database tables and populate them with data.
9
23
10
-
## Generated Trackable Entities
24
+
## Server-Side Generated Trackable Entities
25
+
26
+
_Entities are generated with a traditional .NET class library so that you can use the Visual Studio wizard for adding an ADO.NET Entity Data Model, which uses custom T4 templates to generate server-side trackable entities._
27
+
28
+
> **Note**: If you haven't done so already, create a Visual Studio solution either prior to or while adding a class library project.
11
29
12
30
- Add a .NET 4.6.1 Class Library project called _NetCoreSample.Entities.Generated_.
13
31
+ Open project prpoperties and remove ".Generated" from the default namespace.
@@ -16,7 +34,7 @@ Sample solution using Trackable Entities with .NET Core.
16
34
+ EntityFramework
17
35
+ Install TrackableEntities.Common.Core -Pre
18
36
+ TrackableEntities.CodeTemplates.Service.Net45
19
-
> Note: Ignore the compiling transformation error.
37
+
> **Note**: Ignore the compiling transformation error.
20
38
- Edit EntityType.cs.t4 file in the CodeTemplates/EFModelFromDatabase folder.
21
39
+ First go to Tools, Extensions and Updates, and install the Tangible T4 Editor.
22
40
+ Remove the following namespace import: `using System.Data.Entity.Spatial`
@@ -36,7 +54,11 @@ Sample solution using Trackable Entities with .NET Core.
36
54
+ From the Add button dropdown select **Add As Link**.
37
55
+ Build the project.
38
56
39
-
## Data Migrations
57
+
## EF Core Migrations
58
+
59
+
_In this section you will create a new database based on entities generated from the NorthwindSlim database._
60
+
61
+
> **Note**: To perform an EF Core migration you need to first create either an ASP.NET Core app or a .NET Core console app. It is not possible to use a class library for EF Core migrations.
40
62
41
63
- Add a new **ASP.NET Core** web application
42
64
+ Select Web API template targeting .NET Core with ASP.NET Core 2.0.
@@ -115,6 +137,8 @@ Sample solution using Trackable Entities with .NET Core.
115
137
116
138
## Web API Controllers
117
139
140
+
_This sample uses the .NET Core CLI for scaffolding Web API contollers with GET, POST, PUT and DELETE actions that use Entity Framework Core for persisting changes to the database in a disconnected manner._
141
+
118
142
- Update `Startup.ConfigureServices` to handle cyclical references when serializing JSON.
119
143
120
144
```csharp
@@ -123,7 +147,7 @@ Sample solution using Trackable Entities with .NET Core.
+ Open a command prompt at the Web project location and run the following:
129
153
@@ -264,7 +288,9 @@ Sample solution using Trackable Entities with .NET Core.
264
288
return Ok();
265
289
```
266
290
267
-
## Console Client
291
+
## Client-Side Generated Trackable Entities
292
+
293
+
_Client-side entities are generated using the Visual Studio wizard for adding an ADO.NET Entity Data Model, even though the client does not require any reference to Entity Framework._
268
294
269
295
- Add a .NET 4.6.1 class library project called _NetCoreSample.Entities.Client_.
270
296
- Install NuGet packages:
@@ -273,6 +299,11 @@ Sample solution using Trackable Entities with .NET Core.
273
299
+ TrackableEntities.CodeTemplates.Client.Net45
274
300
- Add new item, Data, ADO.NET Entity Data Model.
275
301
+ Select the NorthwindSlim data connection
302
+
303
+
## Client Console Application
304
+
305
+
_The client console app uses traditional Trackable Entities NuGet packages, which perform client-side change tracking for marking entities as Added, Modified or Deleted._
306
+
276
307
- Add a .NET 4.6.1 console app called _NetCoreSample.ConsoleClient_.
277
308
- Install NuGet packages:
278
309
+ TrackableEntities.Client
@@ -281,4 +312,10 @@ Sample solution using Trackable Entities with .NET Core.
281
312
- Reference the Entities.Client project.
282
313
- Add private helper methods.
283
314
- Add code to retrieve and update entities.
315
+
+ Retrieve customers
316
+
+ Retrieve customer orders
317
+
+ Create an order with details
318
+
+ Update an existing order with unchanged, added, modified and deleted details
319
+
+ Delete an order and verify that it was deleted
284
320
321
+
> **Note**: Complete code for the client app can be found in the ConsoleClient project of the provided solution.
0 commit comments