EntityTypeConfiguration<TEntityType>.HasRequired<TTargetEntity> Method

[This page is specific to the Entity Framework version 6. The latest version is available as the 'Entity Framework' NuGet package. For more information about Entity Framework, see msdn.com/data/ef.]

Configures a required relationship from this entity type. Instances of the entity type will not be able to be saved to the database unless this relationship is specified. The foreign key in the database will be non-nullable.

Namespace:  System.Data.Entity.ModelConfiguration
Assembly:  EntityFramework (in EntityFramework.dll)

Syntax

'Declaration
<SuppressMessageAttribute("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")> _
<SuppressMessageAttribute("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")> _
Public Function HasRequired(Of TTargetEntity As Class) ( _
    navigationPropertyExpression As Expression(Of Func(Of TEntityType, TTargetEntity)) _
) As RequiredNavigationPropertyConfiguration(Of TEntityType, TTargetEntity)
'Usage
Dim instance As EntityTypeConfiguration 
Dim navigationPropertyExpression As Expression(Of Func(Of TEntityType, TTargetEntity))
Dim returnValue As RequiredNavigationPropertyConfiguration(Of TEntityType, TTargetEntity)

returnValue = instance.HasRequired(navigationPropertyExpression)
[SuppressMessageAttribute("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")]
[SuppressMessageAttribute("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
public RequiredNavigationPropertyConfiguration<TEntityType, TTargetEntity> HasRequired<TTargetEntity>(
    Expression<Func<TEntityType, TTargetEntity>> navigationPropertyExpression
)
where TTargetEntity : class
[SuppressMessageAttribute(L"Microsoft.Design", L"CA1011:ConsiderPassingBaseTypesAsParameters")]
[SuppressMessageAttribute(L"Microsoft.Design", L"CA1006:DoNotNestGenericTypesInMemberSignatures")]
public:
generic<typename TTargetEntity>
where TTargetEntity : ref class 
RequiredNavigationPropertyConfiguration<TEntityType, TTargetEntity>^ HasRequired(
    Expression<Func<TEntityType, TTargetEntity>^>^ navigationPropertyExpression
)
[<SuppressMessageAttribute("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")>]
[<SuppressMessageAttribute("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")>]
member HasRequired : 
        navigationPropertyExpression:Expression<Func<'TEntityType, 'TTargetEntity>> -> RequiredNavigationPropertyConfiguration<'TEntityType, 'TTargetEntity>  when 'TTargetEntity : not struct
JScript does not support generic types and methods.

Type Parameters

  • TTargetEntity
    The type of the entity at the other end of the relationship.

Parameters

Return Value

Type: System.Data.Entity.ModelConfiguration.Configuration.RequiredNavigationPropertyConfiguration<TEntityType, TTargetEntity>
A configuration object that can be used to further configure the relationship.

See Also

Reference

EntityTypeConfiguration<TEntityType> Class

System.Data.Entity.ModelConfiguration Namespace