
Or, can be placed on either the dependent or principal navigation with the name of the property to use as the foreign key. can be placed on the foreign key property with the name of the dependent navigation. ForeignKeyAttributeįoreignKeyAttribute is used to connect a foreign key property with its navigations. Using on the principal navigation side of a relationship has no effect. For example, with the following types, the Post.BlogId property is made non-nullable, and the relationship becomes required. Doing do makes the foreign key not nullable, thereby making the relationship required. In the context of relationships, is usually used on a foreign key property. RequiredAttribute is applied to a property to indicate that the property cannot be null.
#Data annotations entity framework code
However, the Abstractions package is a lightweight package that can be referenced directly by application code without bringing in all of EF Core and its dependencies. This package is included as a dependency whenever the main Microsoft.EntityFrameworkCore package, or one of the associated database provider packages, is used.

These attributes are contained in the NuGet package. All new mapping attributes designed for EF Core are now specific to EF Core, thereby keeping their semantics and use simple and clear. The use of data annotations across many technologies and for both mapping and validation has led to differences in semantics across technologies. These mapping attributes are commonly called "data annotations" and are used by a variety of frameworks, including EF Core, EF6, ASP.NET Core MVC, and so on. NET, and so do not require the installation of any additional NuGet packages. The attributes in these namespaces are included as part of the base framework in all supported versions of. Many mapping attributes come from the and namespaces. The code below can be found in MappingAttributes.cs.
