Share via


EntityTypeConfiguration<TEntityType>.HasOptional<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 an optional relationship from this entity type. Instances of the entity type will be able to be saved to the database without this relationship being specified. The foreign key in the database will be nullable.

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

Syntax

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

returnValue = instance.HasOptional(navigationPropertyExpression)
[SuppressMessageAttribute("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
[SuppressMessageAttribute("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")]
public OptionalNavigationPropertyConfiguration<TEntityType, TTargetEntity> HasOptional<TTargetEntity>(
    Expression<Func<TEntityType, TTargetEntity>> navigationPropertyExpression
)
where TTargetEntity : class
[SuppressMessageAttribute(L"Microsoft.Design", L"CA1006:DoNotNestGenericTypesInMemberSignatures")]
[SuppressMessageAttribute(L"Microsoft.Design", L"CA1011:ConsiderPassingBaseTypesAsParameters")]
public:
generic<typename TTargetEntity>
where TTargetEntity : ref class 
OptionalNavigationPropertyConfiguration<TEntityType, TTargetEntity>^ HasOptional(
    Expression<Func<TEntityType, TTargetEntity>^>^ navigationPropertyExpression
)
[<SuppressMessageAttribute("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")>]
[<SuppressMessageAttribute("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")>]
member HasOptional : 
        navigationPropertyExpression:Expression<Func<'TEntityType, 'TTargetEntity>> -> OptionalNavigationPropertyConfiguration<'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.OptionalNavigationPropertyConfiguration<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