Table of Contents

Class NavigationPropertyAnalyzer

Namespace
ProjGraph.Lib.EntityFramework.Infrastructure
Assembly
ProjGraph.Lib.EntityFramework.dll

Provides methods for analyzing navigation properties in entity types.

public static class NavigationPropertyAnalyzer
Inheritance
NavigationPropertyAnalyzer
Inherited Members

Remarks

The NavigationPropertyAnalyzer class contains static methods to analyze and determine the characteristics of navigation properties in entity types, such as whether they are collections, have inverse references, or are valid entity candidates.

Methods

HasInverseCollection(IPropertySymbol, INamedTypeSymbol)

Determines whether the specified property has an inverse collection navigation property in the target type.

public static bool HasInverseCollection(IPropertySymbol prop, INamedTypeSymbol targetType)

Parameters

prop IPropertySymbol

The IPropertySymbol representing the property to check.

targetType INamedTypeSymbol

The INamedTypeSymbol representing the target type to search for an inverse collection.

Returns

bool

true if the target type contains a collection navigation property that references the source type; otherwise, false.

Remarks

This method checks the members of the target type to find a property that is a collection navigation property and references the source type of the provided property.

HasInverseReference(IPropertySymbol, INamedTypeSymbol)

Determines whether the specified property has an inverse reference navigation property in the target type.

public static bool HasInverseReference(IPropertySymbol prop, INamedTypeSymbol targetType)

Parameters

prop IPropertySymbol

The IPropertySymbol representing the property to check.

targetType INamedTypeSymbol

The INamedTypeSymbol representing the target type to search for an inverse reference.

Returns

bool

true if the target type contains a non-collection navigation property that references the source type; otherwise, false.

Remarks

This method checks the members of the target type to find a property that is a non-collection navigation property and references the source type of the provided property.

IsNavigationProperty(IPropertySymbol, out INamedTypeSymbol?, out bool)

Determines whether the specified property is a navigation property and retrieves its target type and collection status.

public static bool IsNavigationProperty(IPropertySymbol prop, out INamedTypeSymbol? targetType, out bool isCollection)

Parameters

prop IPropertySymbol

The IPropertySymbol representing the property to evaluate.

targetType INamedTypeSymbol

When this method returns, contains the target type of the navigation property if it is valid; otherwise, null.

isCollection bool

When this method returns, indicates whether the navigation property is a collection.

Returns

bool

true if the property is a navigation property; otherwise, false.

Remarks

This method determines if the given property is a navigation property by checking its type. If the property is a generic collection type, it extracts the element type and sets the isCollection flag to true. If the property is not a collection, it checks if the type is a valid entity candidate.