Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions entity-framework/core/get-started/winforms.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ The screen shots and code listings in this walkthrough are taken from Visual Stu

You need to have Visual Studio 2022 17.3 or later installed with the **.NET desktop workload** selected to complete this walkthrough. For more information about installing the latest version of Visual Studio, see [Install Visual Studio](/visualstudio/install/install-visual-studio).

## Create the Application
## Create the application

1. Open Visual Studio
2. On the start window, choose **Create new project**.
Expand Down Expand Up @@ -48,7 +48,7 @@ You need to have Visual Studio 2022 17.3 or later installed with the **.NET desk
> [!NOTE]
> The **Microsoft.EntityFrameworkCore.Sqlite** is the "database provider" package for using EF Core with a SQLite database. Similar packages are available for other database systems. Installing a database provider package automatically brings in all the dependencies needed to use EF Core with that database system. This includes the **Microsoft.EntityFrameworkCore** base package.

## Define a Model
## Define a model

In this walkthrough we will implement a model using "Code First". This means that EF Core will create the database tables and schema based on the C# classes you define. See [Managing Database Schemas](xref:core/managing-schemas/index) to see how to use an existing database instead.

Expand Down
20 changes: 10 additions & 10 deletions entity-framework/core/get-started/wpf.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ The screen shots and code listings in this walkthrough are taken from Visual Stu
> [!TIP]
> You can view this article's [sample on GitHub](https://github.com/dotnet/EntityFramework.Docs/tree/main/samples/core/WPF).

## Pre-Requisites
## Pre-requisites

You need to have Visual Studio 2019 16.3 or later installed with the **.NET desktop workload** selected to complete this walkthrough. For more information about installing the latest version of Visual Studio, see [Install Visual Studio](/visualstudio/install/install-visual-studio).

## Create the Application
## Create the application

1. Open Visual Studio
2. On the start window, choose **Create new project**.
Expand All @@ -45,7 +45,7 @@ You need to have Visual Studio 2019 16.3 or later installed with the **.NET desk
> [!NOTE]
> When you installed the Sqlite package, it automatically pulled down the related **Microsoft.EntityFrameworkCore** base package. The **Microsoft.EntityFrameworkCore.Proxies** package provides support for "lazy-loading" data. This means when you have entities with child entities, only the parents are fetched on the initial load. The proxies detect when an attempt to access the child entities is made and automatically loads them on demand.

## Define a Model
## Define a model

In this walkthrough you will implement a model using "code first." This means that EF Core will create the database tables and schema based on the C# classes you define.

Expand Down Expand Up @@ -83,15 +83,15 @@ Press **CTRL+SHIFT+B** or navigate to **Build > Build Solution** to compile t
> [!TIP]
> 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
## Lazy loading

The **Products** property on the **Category** class and **Category** property on the **Product** class are navigation properties. In Entity Framework Core, navigation properties provide a way to navigate a relationship between two entity types.

EF Core gives you an option of loading related entities from the database automatically the first time you access the navigation property. With this type of loading (called lazy loading), be aware that the first time you access each navigation property a separate query will be executed against the database if the contents are not already in the context.

When using "Plain Old C# Object" (POCO) entity types, EF Core achieves lazy loading by creating instances of derived proxy types during runtime and then overriding virtual properties in your classes to add the loading hook. To get lazy loading of related objects, you must declare navigation property getters as **public** and **virtual** (**Overridable** in Visual Basic), and your class must not be **sealed** (**NotOverridable** in Visual Basic). When using Database First, navigation properties are automatically made virtual to enable lazy loading.

## Bind Object to Controls
## Bind object to controls

Add the classes that are defined in the model as data sources for this WPF application.

Expand All @@ -108,7 +108,7 @@ Add the classes that are defined in the model as data sources for this WPF appli

1. Note that the `CategoryId` is set to `ReadOnly` because it is assigned by the database and cannot be changed.

## Adding a Details Grid
## Adding a details grid

Now that the grid exists to display categories, the details grid can be added to show products. Add this inside the
`Grid` element, after the categories `DataGrid` element.
Expand All @@ -125,7 +125,7 @@ Your design view should look like this:

![Screenshot of WPF Designer](_static/wpf-tutorial-designer.jpg)

## Add Code that Handles Data Interaction
## Add code that handles data interaction

It's time to add some event handlers to the main window.

Expand All @@ -145,13 +145,13 @@ The code declares a long-running instance of `ProductContext`. The `ProductConte
> [!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](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
## Test the WPF application

Compile and run the application by pressing **F5** or choosing **Debug > Start Debugging**. The database should be automatically created with a file named `products.db`. Enter a category name and hit enter, then add products to the lower grid. Click save and watch the grid refresh with the database provided ids. Highlight a row and hit **Delete** to remove the row. The entity will be deleted when you click **Save**.

![Running application](_static/wpf-tutorial-app.jpg)

## Property Change Notification
## Property change notification

This example relies on four steps to synchronize the entities with the UI.

Expand All @@ -165,6 +165,6 @@ This works for our getting started sample, but you may require additional code f
> [!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
## Next steps

Learn more about [Configuring a DbContext](xref:core/dbcontext-configuration/index).
2 changes: 1 addition & 1 deletion entity-framework/core/modeling/bulk-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Properties of this type are not discovered by default as the current EF provider

[!code-csharp[Main](../../../samples/core/Modeling/BulkConfiguration/CurrencyConverter.cs?name=CurrencyConverter)]

### Drawbacks of the Metadata API
### Drawbacks of the metadata API

- Unlike [Fluent API](xref:core/modeling/index#use-fluent-api-to-configure-a-model), every modification to the model needs to be done explicitly. For example, if some of the `Currency` properties were configured as navigations by a convention then you need to first remove the navigation referencing the CLR property before adding an entity type property for it. [#9117](https://github.com/dotnet/efcore/issues/9117) will improve this.
- The conventions run after each change. If you remove a navigation discovered by a convention then the convention will run again and could add it back. To prevent this from happening you would need to either delay the conventions until after the property is added by calling <xref:Microsoft.EntityFrameworkCore.Metadata.Conventions.IConventionContext.DelayConventions> and later disposing the returned object or to mark the CLR property as ignored using <xref:Microsoft.EntityFrameworkCore.Metadata.IMutableModel.AddIgnored*>.
Expand Down
2 changes: 1 addition & 1 deletion entity-framework/core/modeling/entity-properties.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ In the following example, configuring a maximum length of 500 will cause a colum

***

### Precision and Scale
### Precision and scale

Some relational data types support the precision and scale facets; these control what values can be stored, and how much storage is needed for the column. Which data types support precision and scale is database-dependent, but in most databases `decimal` and `DateTime` types do support these facets. For `decimal` properties, precision defines the maximum number of digits needed to express any value the column will contain, and scale defines the maximum number of decimal places needed. For `DateTime` properties, precision defines the maximum number of digits needed to express fractions of seconds, and scale is not used.

Expand Down
2 changes: 1 addition & 1 deletion entity-framework/core/modeling/keyless-entity-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ uid: core/modeling/keyless-entity-types

In addition to regular entity types, an EF Core model can contain _keyless entity types_, which can be used to carry out database queries against data that doesn't contain key values.

## Defining Keyless entity types
## Defining keyless entity types

Keyless entity types can be defined as follows:

Expand Down
2 changes: 1 addition & 1 deletion entity-framework/core/modeling/keys.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ Key properties must always have a non-default value when adding a new entity to
> [!IMPORTANT]
> If a key property has its value generated by the database and a non-default value is specified when an entity is added, then EF will assume that the entity already exists in the database and will try to update it instead of inserting a new one. To avoid this, turn off value generation or see [how to specify explicit values for generated properties](xref:core/modeling/generated-properties#overriding-value-generation).

## Alternate Keys
## Alternate keys

An alternate key serves as an alternate unique identifier for each entity instance in addition to the primary key; it can be used as the target of a relationship. When using a relational database this maps to the concept of a unique index/constraint on the alternate key column(s) and one or more foreign key constraints that reference the column(s).

Expand Down
6 changes: 3 additions & 3 deletions entity-framework/core/modeling/spatial.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ There are several spatial data types. Which type you use depends on the types of

Using the base Geometry type allows any type of shape to be specified by the property.

## Longitude and Latitude
## Longitude and latitude

Coordinates in NTS are in terms of X and Y values. To represent longitude and latitude, use X for longitude and Y for latitude. Note that this is **backwards** from the `latitude, longitude` format in which you typically see these values.

## Querying Data
## Querying data

The following entity classes could be used to map to tables in the [Wide World Importers sample database](https://go.microsoft.com/fwlink/?LinkID=800630).

Expand All @@ -74,7 +74,7 @@ In LINQ, the NTS methods and properties available as database functions will be

The spatial NuGet packages also enable [reverse engineering](xref:core/managing-schemas/scaffolding) models with spatial properties, but you need to install the package ***before*** running `Scaffold-DbContext` or `dotnet ef dbcontext scaffold`. If you don't, you'll receive warnings about not finding type mappings for the columns and the columns will be skipped.

## SRID Ignored during client operations
## SRID ignored during client operations

NTS ignores SRID values during operations. It assumes a planar coordinate system. This means that if you specify coordinates in terms of longitude and latitude, some client-evaluated values like distance, length, and area will be in degrees, not meters. For more meaningful values, you first need to project the coordinates to another coordinate system using a library like [ProjNet (for GeoAPI)](https://github.com/NetTopologySuite/ProjNet4GeoAPI).

Expand Down
2 changes: 1 addition & 1 deletion entity-framework/core/querying/complex-query-operators.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ ORDER BY [b].[Price]

In this case, the GroupBy operator doesn't translate directly to a `GROUP BY` clause in the SQL, but instead, EF Core creates the groupings after the results are returned from the server.

## Left Join
## Left join

While Left Join isn't a LINQ operator, relational databases have the concept of a Left Join which is frequently used in queries. A particular pattern in LINQ queries gives the same result as a `LEFT JOIN` on the server. EF Core identifies such patterns and generates the equivalent `LEFT JOIN` on the server side. The pattern involves creating a GroupJoin between both the data sources and then flattening out the grouping by using the SelectMany operator with DefaultIfEmpty on the grouping source to match null when the inner doesn't have a related element. The following example shows what that pattern looks like and what it generates.

Expand Down
2 changes: 1 addition & 1 deletion entity-framework/core/querying/sql-queries.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ Composing with LINQ requires your SQL query to be composable, since EF Core will

SQL Server doesn't allow composing over stored procedure calls, so any attempt to apply additional query operators to such a call will result in invalid SQL. Use <xref:System.Linq.Enumerable.AsEnumerable*> or <xref:Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.AsAsyncEnumerable*> right after <xref:Microsoft.EntityFrameworkCore.RelationalQueryableExtensions.FromSql*> or <xref:Microsoft.EntityFrameworkCore.RelationalQueryableExtensions.FromSqlRaw*> to make sure that EF Core doesn't try to compose over a stored procedure.

## Change Tracking
## Change tracking

Queries that use <xref:Microsoft.EntityFrameworkCore.RelationalQueryableExtensions.FromSql*> or <xref:Microsoft.EntityFrameworkCore.RelationalQueryableExtensions.FromSqlRaw*> follow the exact same change tracking rules as any other LINQ query in EF Core. For example, if the query projects entity types, the results are tracked by default.

Expand Down
2 changes: 1 addition & 1 deletion entity-framework/core/saving/basic.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Use the <xref:Microsoft.EntityFrameworkCore.DbSet`1.Remove*?displayProperty=name

If the entity already exists in the database, it will be deleted during `SaveChanges`. If the entity has not yet been saved to the database (that is, it is tracked as added) then it will be removed from the context and will no longer be inserted when `SaveChanges` is called.

## Multiple Operations in a single SaveChanges
## Multiple operations in a single SaveChanges

You can combine multiple Add/Update/Remove operations into a single call to `SaveChanges`:

Expand Down