Skip to content

Commit 30e21af

Browse files
author
Anthony Sneed
committed
Update ReadMe.
1 parent 01d6363 commit 30e21af

1 file changed

Lines changed: 44 additions & 7 deletions

File tree

README.md

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,31 @@
1-
## Trackable Entities Core Sample
1+
# Trackable Entities for EF Core Sample
22

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.
416

517
## NorthwindSlim Database
618

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+
721
- This sample uses a skinny version of the Northwind sample database, called _NorthwindSlim_, which you can download from http://bit.ly/northwindslim.
822
- 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.
923

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.
1129
1230
- Add a .NET 4.6.1 Class Library project called _NetCoreSample.Entities.Generated_.
1331
+ Open project prpoperties and remove ".Generated" from the default namespace.
@@ -16,7 +34,7 @@ Sample solution using Trackable Entities with .NET Core.
1634
+ EntityFramework
1735
+ Install TrackableEntities.Common.Core -Pre
1836
+ TrackableEntities.CodeTemplates.Service.Net45
19-
> Note: Ignore the compiling transformation error.
37+
> **Note**: Ignore the compiling transformation error.
2038
- Edit EntityType.cs.t4 file in the CodeTemplates/EFModelFromDatabase folder.
2139
+ First go to Tools, Extensions and Updates, and install the Tangible T4 Editor.
2240
+ Remove the following namespace import: `using System.Data.Entity.Spatial`
@@ -36,7 +54,11 @@ Sample solution using Trackable Entities with .NET Core.
3654
+ From the Add button dropdown select **Add As Link**.
3755
+ Build the project.
3856

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.
4062
4163
- Add a new **ASP.NET Core** web application
4264
+ 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.
115137

116138
## Web API Controllers
117139

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+
118142
- Update `Startup.ConfigureServices` to handle cyclical references when serializing JSON.
119143

120144
```csharp
@@ -123,7 +147,7 @@ Sample solution using Trackable Entities with .NET Core.
123147
options.SerializerSettings.PreserveReferencesHandling = PreserveReferencesHandling.All);
124148
```
125149

126-
- Use the DotNet CLI to scaffold a Customer controller
150+
- Use the DotNet CLI to scaffold a Customer controller.
127151
+ Install NuGet package: Microsoft.VisualStudio.Web.CodeGeneration.Design
128152
+ Open a command prompt at the Web project location and run the following:
129153

@@ -264,7 +288,9 @@ Sample solution using Trackable Entities with .NET Core.
264288
return Ok();
265289
```
266290

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._
268294

269295
- Add a .NET 4.6.1 class library project called _NetCoreSample.Entities.Client_.
270296
- Install NuGet packages:
@@ -273,6 +299,11 @@ Sample solution using Trackable Entities with .NET Core.
273299
+ TrackableEntities.CodeTemplates.Client.Net45
274300
- Add new item, Data, ADO.NET Entity Data Model.
275301
+ 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+
276307
- Add a .NET 4.6.1 console app called _NetCoreSample.ConsoleClient_.
277308
- Install NuGet packages:
278309
+ TrackableEntities.Client
@@ -281,4 +312,10 @@ Sample solution using Trackable Entities with .NET Core.
281312
- Reference the Entities.Client project.
282313
- Add private helper methods.
283314
- 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
284320

321+
> **Note**: Complete code for the client app can be found in the ConsoleClient project of the provided solution.

0 commit comments

Comments
 (0)