From 98e132b0538ed9915bf75c16a8a8637c87077fd9 Mon Sep 17 00:00:00 2001 From: Smit Patel Date: Tue, 1 Sep 2020 18:38:12 -0700 Subject: [PATCH] Clean up links (part 1) (#2603) Part of #2447 --- entity-framework/core/get-started/wpf.md | 12 +- .../core/managing-schemas/index.md | 2 +- .../core/what-is-new/ef-core-5.0/whatsnew.md | 10 +- .../connection-resiliency/commit-failures.md | 9 +- .../ef6/fundamentals/databinding/winforms.md | 1 + .../ef6/fundamentals/databinding/wpf.md | 135 +++++++++--------- .../disconnected-entities/index.md | 7 +- entity-framework/ef6/fundamentals/install.md | 2 +- .../testing/testability-article.md | 6 +- entity-framework/efcore-and-ef6/index.md | 3 +- entity-framework/index.yml | 12 +- 11 files changed, 103 insertions(+), 96 deletions(-) diff --git a/entity-framework/core/get-started/wpf.md b/entity-framework/core/get-started/wpf.md index 813c319331..0dde5b71fd 100644 --- a/entity-framework/core/get-started/wpf.md +++ b/entity-framework/core/get-started/wpf.md @@ -75,14 +75,14 @@ Add a new `ProductContext.cs` class to the project with the following definition [!code-csharp[](../../../samples/core/WPF/GetStartedWPF/GetStartedWPF/ProductContext.cs)] * The `DbSet` informs EF Core what C# entities should be mapped to the database. -* There are a variety of ways to configure the EF Core `DbContext`. You can read about them in: [Configuring a DbContext](/ef/core/miscellaneous/configuring-dbcontext). +* There are a variety of ways to configure the EF Core `DbContext`. You can read about them in: [Configuring a DbContext](xref:core/miscellaneous/configuring-dbcontext). * This example uses the `OnConfiguring` override to specify a Sqlite data file. * The `UseLazyLoadingProxies` call tells EF Core to implement lazy-loading, so child entities are automatically loaded when accessed from the parent. Press **CTRL+SHIFT+B** or navigate to **Build > Build Solution** to compile the project. > [!TIP] -> Learn about the different was to keep your database and EF Core models in sync: [Managing Database Schemas](/ef/core/managing-schemas). +> Learn about the different was to keep your database and EF Core models in sync: [Managing Database Schemas](xref:core/managing-schemas/index). ## Lazy Loading @@ -143,7 +143,7 @@ The code declares a long-running instance of `ProductContext`. The `ProductConte [!code-csharp[](../../../samples/core/WPF/GetStartedWPF/GetStartedWPF/MainWindow.xaml.cs)] > [!NOTE] -> The code uses a call to `EnsureCreated()` to build the database on the first run. This is acceptable for demos, but in production apps you should look at [migrations](/ef/core/managing-schemas/migrations/) to manage your schema. The code also executes synchronously because it uses a local SQLite database. For production scenarios that typically involve a remote server, consider using the asynchronous versions of the `Load` and `SaveChanges` methods. +> The code uses a call to `EnsureCreated()` to build the database on the first run. This is acceptable for demos, but in production apps you should look at [migrations](xref:core/managing-schemas/migrations/index) to manage your schema. The code also executes synchronously because it uses a local SQLite database. For production scenarios that typically involve a remote server, consider using the asynchronous versions of the `Load` and `SaveChanges` methods. ## Test the WPF Application @@ -153,18 +153,18 @@ Compile and run the application by pressing **F5** or choosing **Debug > Star ## Property Change Notification -This example relies on four steps to synchronize the entities with the UI. +This example relies on four steps to synchronize the entities with the UI. 1. The initial call `_context.Categories.Load()` loads the categories data. 1. The lazy-loading proxies load the dependent products data. 1. EF Core's built-in change tracking makes the necessary modifications to entities, including insertions and deletions, when `_context.SaveChanges()` is called. 1. The calls to `DataGridView.Items.Refresh()` force a reload with the newly generated ids. -This works for our getting started sample, but you may require additional code for other scenarios. WPF controls render the UI by reading the fields and properties on your entities. When you edit a value in the user interface (UI), that value is passed to your entity. When you change the value of a property directly on your entity, such as loading it from the database, WPF will not immediately reflect the changes in the UI. The rendering engine must be notified of the changes. The project did this by manually calling `Refresh()`. An easy way to automate this notification is by implementing the [INotifyPropertyChanged](/dotnet/api/system.componentmodel.inotifypropertychanged) interface. WPF components will automatically detect the interface and register for change events. The entity is responsible for raising these events. +This works for our getting started sample, but you may require additional code for other scenarios. WPF controls render the UI by reading the fields and properties on your entities. When you edit a value in the user interface (UI), that value is passed to your entity. When you change the value of a property directly on your entity, such as loading it from the database, WPF will not immediately reflect the changes in the UI. The rendering engine must be notified of the changes. The project did this by manually calling `Refresh()`. An easy way to automate this notification is by implementing the [INotifyPropertyChanged](/dotnet/api/system.componentmodel.inotifypropertychanged) interface. WPF components will automatically detect the interface and register for change events. The entity is responsible for raising these events. > [!TIP] > To learn more about how to handle changes, read: [How to implement property change notification](/dotnet/framework/wpf/data/how-to-implement-property-change-notification). ## Next Steps -Learn more about [Configuring a DbContext](/ef/core/miscellaneous/configuring-dbcontext). \ No newline at end of file +Learn more about [Configuring a DbContext](xref:core/miscellaneous/configuring-dbcontext). diff --git a/entity-framework/core/managing-schemas/index.md b/entity-framework/core/managing-schemas/index.md index 1f74b21b9f..60da52acfa 100644 --- a/entity-framework/core/managing-schemas/index.md +++ b/entity-framework/core/managing-schemas/index.md @@ -2,6 +2,7 @@ title: Managing Database Schemas - EF Core author: bricelam ms.date: 10/30/2017 +uid: core/managing-schemas/index --- # Managing Database Schemas @@ -19,7 +20,6 @@ scaffold a DbContext and the entity type classes by reverse engineering your dat > The [create and drop APIs][3] can also create the database schema from your EF Core model. However, they are primarily > for testing, prototyping, and other scenarios where dropping the database is acceptable. - [1]: migrations/index.md [2]: scaffolding.md [3]: ensure-created.md diff --git a/entity-framework/core/what-is-new/ef-core-5.0/whatsnew.md b/entity-framework/core/what-is-new/ef-core-5.0/whatsnew.md index a545a1228b..2d2ac4ae19 100644 --- a/entity-framework/core/what-is-new/ef-core-5.0/whatsnew.md +++ b/entity-framework/core/what-is-new/ef-core-5.0/whatsnew.md @@ -967,7 +967,7 @@ See the [Configuring Navigation Properties documentation](xref:core/modeling/rel Migrations and scaffolding now allow namespaces to be specified on the command line. For example, to reverse engineer a database putting the context and model classes in different namespaces: -``` +```dotnetcli dotnet ef dbcontext scaffold "connection string" Microsoft.EntityFrameworkCore.SqlServer --context-namespace "My.Context" --namespace "My.Model" ``` @@ -976,7 +976,7 @@ See the [Migrations](xref:core/managing-schemas/migrations/index#namespaces) and --- Also, a connection string can now be passed to the `database-update` command: -``` +```dotnetcli dotnet ef database update --connection "connection string" ``` @@ -991,6 +991,7 @@ For performance reasons, EF doesn't do additional null-checks when reading value Using `EnableDetailedErrors` will add extra null checking to queries such that, for a small performance overhead, these errors are easier to trace back to a root cause. For example: + ```CSharp protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) => optionsBuilder @@ -1016,6 +1017,7 @@ Documentation is tracked by issue [#2199](https://github.com/dotnet/EntityFramew ### Support for the SQL Server DATALENGTH function This can be accessed using the new `EF.Functions.DataLength` method. For example: + ```CSharp var count = context.Orders.Count(c => 100 < EF.Functions.DataLength(c.OrderDate)); ``` @@ -1046,7 +1048,7 @@ Documentation is tracked by issue [#2230](https://github.com/dotnet/EntityFramew ### Complete discriminator mapping -EF Core uses a discriminator column for [TPH mapping of an inheritance hierarchy](/ef/core/modeling/inheritance). Some performance enhancements are possible so long as EF Core knows all possible values for the discriminator. EF Core 5.0 now implements these enhancements. +EF Core uses a discriminator column for [TPH mapping of an inheritance hierarchy](xref:core/modeling/inheritance). Some performance enhancements are possible so long as EF Core knows all possible values for the discriminator. EF Core 5.0 now implements these enhancements. For example, previous versions of EF Core would always generate this SQL for a query returning all types in a hierarchy: @@ -1174,7 +1176,7 @@ The Azure Cosmos DB database provider now supports optimistic concurrency using builder.Entity().Property(c => c.ETag).IsEtagConcurrency(); ``` -SaveChanges will then throw an `DbUpdateConcurrencyException` on a concurrency conflict, which [can be handled](/ef/core/saving/concurrency) to implement retries, etc. +SaveChanges will then throw an `DbUpdateConcurrencyException` on a concurrency conflict, which [can be handled](xref:core/saving/concurrency) to implement retries, etc. Documentation is tracked by issue [#2099](https://github.com/dotnet/EntityFramework.Docs/issues/2099). diff --git a/entity-framework/ef6/fundamentals/connection-resiliency/commit-failures.md b/entity-framework/ef6/fundamentals/connection-resiliency/commit-failures.md index 181c07f15f..9362555d10 100644 --- a/entity-framework/ef6/fundamentals/connection-resiliency/commit-failures.md +++ b/entity-framework/ef6/fundamentals/connection-resiliency/commit-failures.md @@ -5,10 +5,11 @@ ms.date: "10/23/2016" ms.assetid: 5b1f7a7d-1b24-4645-95ec-5608a31ef577 --- # Handling transaction commit failures + > [!NOTE] > **EF6.1 Onwards Only** - The features, APIs, etc. discussed in this page were introduced in Entity Framework 6.1. If you are using an earlier version, some or all of the information does not apply. -As part of 6.1 we are introducing a new connection resiliency feature for EF: the ability to detect and recover automatically when transient connection failures affect the acknowledgement of transaction commits. The full details of the scenario are best described in the blog post [SQL Database Connectivity and the Idempotency Issue](https://docs.microsoft.com/archive/blogs/adonet/sql-database-connectivity-and-the-idempotency-issue). In summary, the scenario is that when an exception is raised during a transaction commit there are two possible causes: +As part of 6.1 we are introducing a new connection resiliency feature for EF: the ability to detect and recover automatically when transient connection failures affect the acknowledgement of transaction commits. The full details of the scenario are best described in the blog post [SQL Database Connectivity and the Idempotency Issue](/archive/blogs/adonet/sql-database-connectivity-and-the-idempotency-issue). In summary, the scenario is that when an exception is raised during a transaction commit there are two possible causes: 1. The transaction commit failed on the server 2. The transaction commit succeeded on the server but a connectivity issue prevented the success notification from reaching the client @@ -59,8 +60,8 @@ Before EF 6.1 there was not mechanism to handle commit failures in the EF produc 1. Add a non-tracked table to the database used to track the status of the transactions. 2. Insert a row into the table at the beginning of each transaction. 3. If the connection fails during the commit, check for the presence of the corresponding row in the database. - - If the row is present, continue normally, as the transaction was committed successfully - - If the row is absent, use an execution strategy to retry the current operation. + * If the row is present, continue normally, as the transaction was committed successfully + * If the row is absent, use an execution strategy to retry the current operation. 4. If the commit is successful, delete the corresponding row to avoid the growth of the table. -[This blog post](https://docs.microsoft.com/archive/blogs/adonet/sql-database-connectivity-and-the-idempotency-issue) contains sample code for accomplishing this on SQL Azure. +[This blog post](/archive/blogs/adonet/sql-database-connectivity-and-the-idempotency-issue) contains sample code for accomplishing this on SQL Azure. diff --git a/entity-framework/ef6/fundamentals/databinding/winforms.md b/entity-framework/ef6/fundamentals/databinding/winforms.md index 6ddac1e471..1af5fb34df 100644 --- a/entity-framework/ef6/fundamentals/databinding/winforms.md +++ b/entity-framework/ef6/fundamentals/databinding/winforms.md @@ -3,6 +3,7 @@ title: "Databinding with WinForms - EF6" author: divega ms.date: "10/23/2016" ms.assetid: 80fc5062-2f1c-4dbd-ab6e-b99496784b36 +uid: ef6/fundamentals/databinding/winforms --- # Databinding with WinForms This step-by-step walkthrough shows how to bind POCO types to Window Forms (WinForms) controls in a “master-detail" form. The application uses Entity Framework to populate objects with data from the database, track changes, and persist data to the database. diff --git a/entity-framework/ef6/fundamentals/databinding/wpf.md b/entity-framework/ef6/fundamentals/databinding/wpf.md index 84718000c6..4a0573214d 100644 --- a/entity-framework/ef6/fundamentals/databinding/wpf.md +++ b/entity-framework/ef6/fundamentals/databinding/wpf.md @@ -3,13 +3,14 @@ title: "Databinding with WPF - EF6" author: divega ms.date: "05/19/2020" ms.assetid: e90d48e6-bea7785-47ef-b756-7b89cce4daf0 +uid: ef6/fundamentals/databinding/wpf --- # Databinding with WPF > [!IMPORTANT] > **This document is valid for WPF on the .NET Framework only** > -> This document describes databinding for WPF on the .NET Framework. For new .NET Core projects, we recommend you use [EF Core](/ef/core) instead of Entity Framework 6. The documentation for databinding in EF Core is here: [Getting Started with WPF](/ef/core/get-started/wpf). +> This document describes databinding for WPF on the .NET Framework. For new .NET Core projects, we recommend you use [EF Core](xref:core/index) instead of Entity Framework 6. The documentation for databinding in EF Core is here: [Getting Started with WPF](xref:core/get-started/wpf). This step-by-step walkthrough shows how to bind POCO types to WPF controls in a “master-detail" form. The application uses the Entity Framework APIs to populate objects with data from the database, track changes, and persist data to the database. @@ -31,22 +32,22 @@ If needed, you can [revert to ObjectContext based code generation](~/ef6/modelin You need to have Visual Studio 2013, Visual Studio 2012 or Visual Studio 2010 installed to complete this walkthrough. -If you are using Visual Studio 2010, you also have to install NuGet. For more information, see [Installing NuGet](https://docs.microsoft.com/nuget/install-nuget-client-tools).   +If you are using Visual Studio 2010, you also have to install NuGet. For more information, see [Installing NuGet](/nuget/install-nuget-client-tools).   ## Create the Application -- Open Visual Studio -- **File -> New -> Project….** -- Select **Windows** in the left pane and **WPFApplication** in the right pane -- Enter **WPFwithEFSample** as the name -- Select **OK** +- Open Visual Studio +- **File -> New -> Project….** +- Select **Windows** in the left pane and **WPFApplication** in the right pane +- Enter **WPFwithEFSample** as the name +- Select **OK** ## Install the Entity Framework NuGet package -- In Solution Explorer, right-click on the **WinFormswithEFSample** project -- Select **Manage NuGet Packages…** -- In the Manage NuGet Packages dialog, Select the **Online** tab and choose the **EntityFramework** package -- Click **Install** +- In Solution Explorer, right-click on the **WinFormswithEFSample** project +- Select **Manage NuGet Packages…** +- In the Manage NuGet Packages dialog, Select the **Online** tab and choose the **EntityFramework** package +- Click **Install** >[!NOTE] > In addition to the EntityFramework assembly a reference to System.ComponentModel.DataAnnotations is also added. If the project has a reference to System.Data.Entity, then it will be removed when the EntityFramework package is installed. The System.Data.Entity assembly is no longer used for Entity Framework 6 applications. @@ -60,11 +61,11 @@ This section shows how to create a model and its associated database using Code When using Code First development you usually begin by writing .NET Framework classes that define your conceptual (domain) model. -- Add a new class to the **WPFwithEFSample:** - - Right-click on the project name - - Select **Add**, then **New Item** - - Select **Class** and enter **Product** for the class name -- Replace the **Product** class definition with the following code: +- Add a new class to the **WPFwithEFSample:** + - Right-click on the project name + - Select **Add**, then **New Item** + - Select **Class** and enter **Product** for the class name +- Replace the **Product** class definition with the following code: ``` csharp namespace WPFwithEFSample @@ -79,7 +80,7 @@ When using Code First development you usually begin by writing .NET Framework cl } } -- Add a **Category** class with the following definition: +- Add a **Category** class with the following definition: using System.Collections.ObjectModel; @@ -106,7 +107,7 @@ In addition to defining entities, you need to define a class that derives from D An instance of the DbContext derived type manages the entity objects during run time, which includes populating objects with data from a database, change tracking, and persisting data to the database. -- Add a new **ProductContext** class to the project with the following definition: +- Add a new **ProductContext** class to the project with the following definition: ``` csharp using System.Data.Entity; @@ -133,29 +134,29 @@ Typically when you are targeting an existing database it will already be created The database server that is installed with Visual Studio is different depending on the version of Visual Studio you have installed: -- If you are using Visual Studio 2010 you'll be creating a SQL Express database. -- If you are using Visual Studio 2012 then you'll be creating a [LocalDB](https://msdn.microsoft.com/library/hh510202.aspx) database. +- If you are using Visual Studio 2010 you'll be creating a SQL Express database. +- If you are using Visual Studio 2012 then you'll be creating a [LocalDB](https://msdn.microsoft.com/library/hh510202.aspx) database. Let's go ahead and generate the database. -- **View -> Server Explorer** -- Right click on **Data Connections -> Add Connection…** -- If you haven’t connected to a database from Server Explorer before you’ll need to select Microsoft SQL Server as the data source +- **View -> Server Explorer** +- Right click on **Data Connections -> Add Connection…** +- If you haven’t connected to a database from Server Explorer before you’ll need to select Microsoft SQL Server as the data source ![Change Data Source](~/ef6/media/changedatasource.png) -- Connect to either LocalDB or SQL Express, depending on which one you have installed, and enter **Products** as the database name +- Connect to either LocalDB or SQL Express, depending on which one you have installed, and enter **Products** as the database name ![Add Connection LocalDB](~/ef6/media/addconnectionlocaldb.png) ![Add Connection Express](~/ef6/media/addconnectionexpress.png) -- Select **OK** and you will be asked if you want to create a new database, select **Yes** +- Select **OK** and you will be asked if you want to create a new database, select **Yes** ![Create Database](~/ef6/media/createdatabase.png) -- The new database will now appear in Server Explorer, right-click on it and select **New Query** -- Copy the following SQL into the new query, then right-click on the query and select **Execute** +- The new database will now appear in Server Explorer, right-click on it and select **New Query** +- Copy the following SQL into the new query, then right-click on the query and select **Execute** ``` SQL CREATE TABLE [dbo].[Categories] ( @@ -180,19 +181,19 @@ Let's go ahead and generate the database. We’re going to make use of Entity Framework Designer, which is included as part of Visual Studio, to create our model. -- **Project -> Add New Item…** -- Select **Data** from the left menu and then **ADO.NET Entity Data Model** -- Enter **ProductModel** as the name and click **OK** -- This launches the **Entity Data Model Wizard** -- Select **Generate from Database** and click **Next** +- **Project -> Add New Item…** +- Select **Data** from the left menu and then **ADO.NET Entity Data Model** +- Enter **ProductModel** as the name and click **OK** +- This launches the **Entity Data Model Wizard** +- Select **Generate from Database** and click **Next** ![Choose Model Contents](~/ef6/media/choosemodelcontents.png) -- Select the connection to the database you created in the first section, enter **ProductContext** as the name of the connection string and click **Next** +- Select the connection to the database you created in the first section, enter **ProductContext** as the name of the connection string and click **Next** ![Choose Your Connection](~/ef6/media/chooseyourconnection.png) -- Click the checkbox next to ‘Tables’ to import all tables and click ‘Finish’ +- Click the checkbox next to ‘Tables’ to import all tables and click ‘Finish’ ![Choose Your Objects](~/ef6/media/chooseyourobjects.png) @@ -202,24 +203,24 @@ Once the reverse engineer process completes the new model is added to your proje If you are working in Visual Studio 2010 then you will need to update the EF designer to use EF6 code generation. -- Right-click on an empty spot of your model in the EF Designer and select **Add Code Generation Item…** -- Select **Online Templates** from the left menu and search for **DbContext** -- Select the **EF 6.x DbContext Generator for C\#,** enter **ProductsModel** as the name and click Add +- Right-click on an empty spot of your model in the EF Designer and select **Add Code Generation Item…** +- Select **Online Templates** from the left menu and search for **DbContext** +- Select the **EF 6.x DbContext Generator for C\#,** enter **ProductsModel** as the name and click Add #### Updating code generation for data binding EF generates code from your model using T4 templates. The templates shipped with Visual Studio or downloaded from the Visual Studio gallery are intended for general purpose use. This means that the entities generated from these templates have simple ICollection<T> properties. However, when doing data binding using WPF it is desirable to use **ObservableCollection** for collection properties so that WPF can keep track of changes made to the collections. To this end we will to modify the templates to use ObservableCollection. -- Open the **Solution Explorer** and find **ProductModel.edmx** file -- Find the **ProductModel.tt** file which will be nested under the ProductModel.edmx file +- Open the **Solution Explorer** and find **ProductModel.edmx** file +- Find the **ProductModel.tt** file which will be nested under the ProductModel.edmx file ![WPF Product Model Template](~/ef6/media/wpfproductmodeltemplate.png) -- Double-click on the ProductModel.tt file to open it in the Visual Studio editor -- Find and replace the two occurrences of “**ICollection**” with “**ObservableCollection**”. These are located approximately at lines 296 and 484. -- Find and replace the first occurrence of “**HashSet**” with “**ObservableCollection**”. This occurrence is located approximately at line 50. **Do not** replace the second occurrence of HashSet found later in the code. -- Find and replace the only occurrence of “**System.Collections.Generic**” with “**System.Collections.ObjectModel**”. This is located approximately at line 424. -- Save the ProductModel.tt file. This should cause the code for entities to be regenerated. If the code does not regenerate automatically, then right click on ProductModel.tt and choose “Run Custom Tool”. +- Double-click on the ProductModel.tt file to open it in the Visual Studio editor +- Find and replace the two occurrences of “**ICollection**” with “**ObservableCollection**”. These are located approximately at lines 296 and 484. +- Find and replace the first occurrence of “**HashSet**” with “**ObservableCollection**”. This occurrence is located approximately at line 50. **Do not** replace the second occurrence of HashSet found later in the code. +- Find and replace the only occurrence of “**System.Collections.Generic**” with “**System.Collections.ObjectModel**”. This is located approximately at line 424. +- Save the ProductModel.tt file. This should cause the code for entities to be regenerated. If the code does not regenerate automatically, then right click on ProductModel.tt and choose “Run Custom Tool”. If you now open the Category.cs file (which is nested under ProductModel.tt) then you should see that the Products collection has the type **ObservableCollection<Product>**. @@ -237,28 +238,28 @@ When using POCO entity types, EF achieves lazy loading by creating instances of Add the classes that are defined in the model as data sources for this WPF application. -- Double-click **MainWindow.xaml** in Solution Explorer to open the main form -- From the main menu, select **Project -> Add New Data Source …** +- Double-click **MainWindow.xaml** in Solution Explorer to open the main form +- From the main menu, select **Project -> Add New Data Source …** (in Visual Studio 2010, you need to select **Data -> Add New Data Source…**) -- In the Choose a Data Source Typewindow, select **Object** and click **Next** -- In the Select the Data Objects dialog, unfold the **WPFwithEFSample** two times and select **Category** +- In the Choose a Data Source Typewindow, select **Object** and click **Next** +- In the Select the Data Objects dialog, unfold the **WPFwithEFSample** two times and select **Category** *There is no need to select the **Product** data source, because we will get to it through the **Product**’s property on the **Category** data source* ![Select Data Objects](~/ef6/media/selectdataobjects.png) -- Click **Finish.** -- The Data Sources window is opened next to the MainWindow.xaml window +- Click **Finish.** +- The Data Sources window is opened next to the MainWindow.xaml window *If the Data Sources window is not showing up, select **View -> Other Windows-> Data Sources*** -- Press the pin icon, so the Data Sources window does not auto hide. You may need to hit the refresh button if the window was already visible. +- Press the pin icon, so the Data Sources window does not auto hide. You may need to hit the refresh button if the window was already visible. ![Data Sources](~/ef6/media/datasources.png) -- Select the **Category** data source and drag it on the form. +- Select the **Category** data source and drag it on the form. The following happened when we dragged this source: -- The **categoryViewSource** resource and the **categoryDataGrid** control were added to XAML -- The DataContext property on the parent Grid element was set to "{StaticResource **categoryViewSource** }". The **categoryViewSource** resource serves as a binding source for the outer\\parent Grid element. The inner Grid elements then inherit the DataContext value from the parent Grid (the categoryDataGrid’s ItemsSource property is set to "{Binding}") +- The **categoryViewSource** resource and the **categoryDataGrid** control were added to XAML +- The DataContext property on the parent Grid element was set to "{StaticResource **categoryViewSource** }". The **categoryViewSource** resource serves as a binding source for the outer\\parent Grid element. The inner Grid elements then inherit the DataContext value from the parent Grid (the categoryDataGrid’s ItemsSource property is set to "{Binding}") ``` xml @@ -283,26 +284,26 @@ The following happened when we dragged this source: Now that we have a grid to display Categories let's add a details grid to display the associated Products. -- Select the **Products** property from under the **Category** data source and drag it on the form. - - The **categoryProductsViewSource** resource and **productDataGrid** grid are added to XAML - - The binding path for this resource is set to Products - - WPF data-binding framework ensures that only Products related to the selected Category show up in **productDataGrid** -- From the Toolbox, drag **Button** on to the form. Set the **Name** property to **buttonSave** and the **Content** property to **Save**. +- Select the **Products** property from under the **Category** data source and drag it on the form. + - The **categoryProductsViewSource** resource and **productDataGrid** grid are added to XAML + - The binding path for this resource is set to Products + - WPF data-binding framework ensures that only Products related to the selected Category show up in **productDataGrid** +- From the Toolbox, drag **Button** on to the form. Set the **Name** property to **buttonSave** and the **Content** property to **Save**. The form should look similar to this: -![Designer](~/ef6/media/designer.png)  +![Designer](~/ef6/media/designer.png) ## Add Code that Handles Data Interaction It's time to add some event handlers to the main window. -- In the XAML window, click on the **<Window** element, this selects the main window -- In the **Properties** window choose **Events** at the top right, then double-click the text box to right of the **Loaded** label +- In the XAML window, click on the **<Window** element, this selects the main window +- In the **Properties** window choose **Events** at the top right, then double-click the text box to right of the **Loaded** label ![Main Window Properties](~/ef6/media/mainwindowproperties.png) -- Also add the **Click** event for the **Save** button by double-clicking the Save button in the designer.  +- Also add the **Click** event for the **Save** button by double-clicking the Save button in the designer. This brings you to the code behind for the form, we'll now edit the code to use the ProductContext to perform data access. Update the code for the MainWindow as shown below. @@ -383,13 +384,13 @@ The code declares a long-running instance of **ProductContext**. The **ProductCo ## Test the WPF Application -- Compile and run the application. If you used Code First, then you will see that a **WPFwithEFSample.ProductContext** database is created for you. -- Enter a category name in the top grid and product names in the bottom grid +- Compile and run the application. If you used Code First, then you will see that a **WPFwithEFSample.ProductContext** database is created for you. +- Enter a category name in the top grid and product names in the bottom grid *Do not enter anything in ID columns, because the primary key is generated by the database* ![Main Window with new categories and products](~/ef6/media/screen1.png) -- Press the **Save** button to save the data to the database +- Press the **Save** button to save the data to the database After the call to DbContext’s **SaveChanges()**, the IDs are populated with the database generated values. Because we called **Refresh()** after **SaveChanges()** the **DataGrid** controls are updated with the new values as well. @@ -397,4 +398,4 @@ After the call to DbContext’s **SaveChanges()**, the IDs are populated with th ## Additional Resources -To learn more about data binding to collections using WPF, see [this topic](https://docs.microsoft.com/dotnet/framework/wpf/data/data-binding-overview#binding-to-collections) in the WPF documentation. +To learn more about data binding to collections using WPF, see [this topic](/dotnet/framework/wpf/data/data-binding-overview#binding-to-collections) in the WPF documentation. diff --git a/entity-framework/ef6/fundamentals/disconnected-entities/index.md b/entity-framework/ef6/fundamentals/disconnected-entities/index.md index 1a81c6caf1..7bcc9e126c 100644 --- a/entity-framework/ef6/fundamentals/disconnected-entities/index.md +++ b/entity-framework/ef6/fundamentals/disconnected-entities/index.md @@ -5,13 +5,14 @@ ms.date: "10/23/2016" ms.assetid: 12138003-a373-4817-b1b7-724130202f5f --- # Working with disconnected entities -In an Entity Framework-based application, a context class is responsible for detecting changes applied to tracked entities. Calling the SaveChanges method persists the changes tracked by the context to the database. When working with n-tier applications, entity objects are usually modified while disconnected from the context, and you must decide how to track changes and report those changes back to the context. This topic discusses different options that are available when using Entity Framework with disconnected entities. + +In an Entity Framework-based application, a context class is responsible for detecting changes applied to tracked entities. Calling the SaveChanges method persists the changes tracked by the context to the database. When working with n-tier applications, entity objects are usually modified while disconnected from the context, and you must decide how to track changes and report those changes back to the context. This topic discusses different options that are available when using Entity Framework with disconnected entities. ## Web service frameworks -Web services technologies typically support patterns that can be used to persist changes on individual disconnected objects. For example, ASP.NET Web API allows you to code controller actions that can include calls to EF to persist changes made to an object on a database. In fact, the Web API tooling in Visual Studio makes it easy to scaffold a Web API controller from your Entity Framework 6 model. For more information, see [using Web API with Entity Framework 6](https://docs.microsoft.com/aspnet/web-api/overview/data/using-web-api-with-entity-framework/). +Web services technologies typically support patterns that can be used to persist changes on individual disconnected objects. For example, ASP.NET Web API allows you to code controller actions that can include calls to EF to persist changes made to an object on a database. In fact, the Web API tooling in Visual Studio makes it easy to scaffold a Web API controller from your Entity Framework 6 model. For more information, see [using Web API with Entity Framework 6](/aspnet/web-api/overview/data/using-web-api-with-entity-framework/). -Historically, there have been several other Web services technologies that offered integration with Entity Framework, like [WCF Data Services](https://docs.microsoft.com/dotnet/framework/data/wcf/create-a-data-service-using-an-adonet-ef-data-wcf) and [RIA Services](https://docs.microsoft.com/previous-versions/dotnet/wcf-ria/ee707344(v=vs.91)). +Historically, there have been several other Web services technologies that offered integration with Entity Framework, like [WCF Data Services](/dotnet/framework/data/wcf/create-a-data-service-using-an-adonet-ef-data-wcf) and [RIA Services](/previous-versions/dotnet/wcf-ria/ee707344(v=vs.91)). ## Low-level EF APIs diff --git a/entity-framework/ef6/fundamentals/install.md b/entity-framework/ef6/fundamentals/install.md index c3a5a88d0d..0e1318f9b6 100644 --- a/entity-framework/ef6/fundamentals/install.md +++ b/entity-framework/ef6/fundamentals/install.md @@ -15,7 +15,7 @@ For some past versions of Visual Studio, updated EF Tools are available as a dow ## EF Runtime -The latest version of Entity Framework is available as the [EntityFramework NuGet package](https://nuget.org/packages/EntityFramework/). If you are not familiar with the NuGet Package Manager, we encourage you to read the [NuGet Overview](https://docs.microsoft.com/nuget/consume-packages/overview-and-workflow). +The latest version of Entity Framework is available as the [EntityFramework NuGet package](https://nuget.org/packages/EntityFramework/). If you are not familiar with the NuGet Package Manager, we encourage you to read the [NuGet Overview](/nuget/consume-packages/overview-and-workflow). ### Installing the EF NuGet Package diff --git a/entity-framework/ef6/fundamentals/testing/testability-article.md b/entity-framework/ef6/fundamentals/testing/testability-article.md index f15157d125..cc342ea72b 100644 --- a/entity-framework/ef6/fundamentals/testing/testability-article.md +++ b/entity-framework/ef6/fundamentals/testing/testability-article.md @@ -192,7 +192,7 @@ With the POCOs in place we can create an Entity Data Model (EDM) in Visual Studi **Figure 1** -Note: if you want to develop the EDM model first, it is possible to generate clean, POCO code from the EDM. You can do this with a Visual Studio 2010 extension provided by the Data Programmability team. To download the extension, launch the Extension Manager from the Tools menu in Visual Studio and search the online gallery of templates for “POCO” (See figure 2). There are several POCO templates available for EF. For more information on using the template, see “ [Walkthrough: POCO Template for the Entity Framework](https://docs.microsoft.com/archive/blogs/adonet/walkthrough-poco-template-for-the-entity-framework)”. +Note: if you want to develop the EDM model first, it is possible to generate clean, POCO code from the EDM. You can do this with a Visual Studio 2010 extension provided by the Data Programmability team. To download the extension, launch the Extension Manager from the Tools menu in Visual Studio and search the online gallery of templates for “POCO” (See figure 2). There are several POCO templates available for EF. For more information on using the template, see “ [Walkthrough: POCO Template for the Entity Framework](/archive/blogs/adonet/walkthrough-poco-template-for-the-entity-framework)”. ![ef test_02](~/ef6/media/eftest-02.png) @@ -958,8 +958,8 @@ In this paper we’ve demonstrated several approaches to creating testable code - Robert C. Martin, “ [The Single Responsibility Principle](https://www.objectmentor.com/resources/articles/srp.pdf)” - Martin Fowler, [Catalog of Patterns](https://www.martinfowler.com/eaaCatalog/index.html) from *Patterns of Enterprise Application Architecture* - Griffin Caprio, “ [Dependency Injection](https://msdn.microsoft.com/magazine/cc163739.aspx)” -- Data Programmability Blog, “ [Walkthrough: Test Driven Development with the Entity Framework 4.0](https://docs.microsoft.com/archive/blogs/adonet/walkthrough-test-driven-development-with-the-entity-framework-4-0)”. -- Data Programmability Blog, “ [Using Repository and Unit of Work patterns with Entity Framework 4.0](https://docs.microsoft.com/archive/blogs/adonet/using-repository-and-unit-of-work-patterns-with-entity-framework-4-0)” +- Data Programmability Blog, “ [Walkthrough: Test Driven Development with the Entity Framework 4.0](/archive/blogs/adonet/walkthrough-test-driven-development-with-the-entity-framework-4-0)”. +- Data Programmability Blog, “ [Using Repository and Unit of Work patterns with Entity Framework 4.0](/archive/blogs/adonet/using-repository-and-unit-of-work-patterns-with-entity-framework-4-0)” - Aaron Jensen, “ [Introducing Machine Specifications](http://codebetter.com/blogs/aaron.jensen/archive/2008/05/08/introducing-machine-specifications-or-mspec-for-short.aspx)” - Eric Lee, “ [BDD with MSTest](https://saintgimp.org/2009/01/20/bdd-with-mstest/)” - Eric Evans, “ [Domain Driven Design](https://books.google.com/books?id=7dlaMs0SECsC&printsec=frontcover&dq=evans%20domain%20driven%20design&hl=en&ei=cHztS6C8KIaglAfA_dS1CA&sa=X&oi=book_result&ct=result&resnum=1&ved=0CCoQ6AEwAA)” diff --git a/entity-framework/efcore-and-ef6/index.md b/entity-framework/efcore-and-ef6/index.md index cc0a745ae0..71f669ad0d 100644 --- a/entity-framework/efcore-and-ef6/index.md +++ b/entity-framework/efcore-and-ef6/index.md @@ -142,13 +142,14 @@ EF6.4 runs on .NET Core and .NET Framework, through multi-targeting. ## Guidance for new applications -Use EF Core on .NET Core for all new applications unless the app needs something that is [only supported on .NET Framework](https://docs.microsoft.com/dotnet/standard/choosing-core-framework-server). +Use EF Core on .NET Core for all new applications unless the app needs something that is [only supported on .NET Framework](/dotnet/standard/choosing-core-framework-server). ## Guidance for existing EF6 applications EF Core is not a drop-in replacement for EF6. Moving from EF6 to EF Core will likely require changes to your application. When moving an EF6 app to .NET Core: + * Keep using EF6 if the data access code is stable and not likely to evolve or need new features. * Port to EF Core if the data access code is evolving or if the app needs new features only available in EF Core. * Porting to EF Core is also often done for performance. However, not all scenarios are faster, so do some profiling first. diff --git a/entity-framework/index.yml b/entity-framework/index.yml index f898dbc3f9..0a51fd9ed1 100644 --- a/entity-framework/index.yml +++ b/entity-framework/index.yml @@ -41,7 +41,7 @@ highlightedContent: # Card - title: "API reference browser" itemType: reference - url: https://docs.microsoft.com/dotnet/api/?view=efcore-3.1 + url: /dotnet/api/?view=efcore-3.1 # Card with summary style additionalContent: @@ -82,17 +82,17 @@ additionalContent: # Card - title: Platforms links: - - url: https://docs.microsoft.com/ef/core/platforms/ + - url: core/platforms/index.md text: "All supported platforms" - - url: https://docs.microsoft.com/aspnet/core/data/ef-rp/intro + - url: /aspnet/core/data/ef-rp/intro text: "ASP.NET Core Razor Pages" - - url: https://docs.microsoft.com/aspnet/core/data/ef-mvc/ + - url: /aspnet/core/data/ef-mvc/ text: "ASP.NET Core MVC" - - url: https://docs.microsoft.com/aspnet/core/blazor/blazor-server-ef-core + - url: /aspnet/core/blazor/blazor-server-ef-core text: "Blazor Server" - url: core/get-started/wpf.md text: "Windows Presentation Foundation (WPF)" - - url: https://docs.microsoft.com/ef/ef6/fundamentals/databinding/winforms/ + - url: ef6/fundamentals/databinding/winforms.md text: "Windows Forms (WinForms)" - url: core/get-started/xamarin.md text: "Xamarin"