Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to disable automatic selection of related schemes #303

Open
lucacivale opened this issue Jul 21, 2022 · 0 comments
Open

Add option to disable automatic selection of related schemes #303

lucacivale opened this issue Jul 21, 2022 · 0 comments
Labels
Feature New feature

Comments

@lucacivale
Copy link

lucacivale commented Jul 21, 2022

Is your feature request related to a problem? Please describe.

When we add a new schema, all referenced schemas are activated automatically. Since entities often refer to each other, many (unneeded) schemas are activated, and proxy classes created.
Since we are working with a huge endpoint, the size of our app would grow. Manually disabling all schemes that are unnecessary would be very tedious. We want to generate only the needed proxy classes.

Example:
Let's say we only want the select the 'FirstEntity'. In this case all three entites would be selected and the proxies created.

<EntityType Name="FirstEntity">
	<NavigationProperty Name="SecondEntity" Type="Collection(Microsoft.Dynamics.DataEntities.SecondEntity)" Partner="FirstEntity">
	</NavigationProperty>
</EntityType>

 <EntityType Name="SecondEntity">
	<NavigationProperty Name="FirstEntity" Type="Microsoft.Dynamics.DataEntities.FirstEntity" Partner="SecondEntity">
	</NavigationProperty>
</EntityType>

 <EntityType Name="ThirdEntity">
	<NavigationProperty Name="SecondEntity" Type="Microsoft.Dynamics.DataEntities.SecondEntity" Partner="ThirdEntity">
	</NavigationProperty>
</EntityType>

Describe the solution you'd like

Create an option to disable the automatic selection. If automatic selection is disabled exclude all properties with type EdmPropertyKind.Navigation.

SchemaTypes.xaml
<StackPanel Margin="0,5,0,5" Orientation="Horizontal">
	<CheckBox Width="16"
			  HorizontalAlignment="Left"
			  VerticalAlignment="Center"
			  Content="Show full name for schema types."
			  IsChecked="{Binding AutoSelectRelatedTypes}" />
	<TextBlock Margin="5,0,0,0" VerticalAlignment="Center">
		Automatically select related schemes.
	</TextBlock>
</StackPanel>
SchemaTypesViewModel.LoadSchemaTypes

IEnumerable<IEdmProperty> properties = AutoSelectRelatedTypes == true ? structuredType.DeclaredProperties
	: structuredType.DeclaredProperties.Where(property => property.PropertyKind != EdmPropertyKind.Navigation);
ODataT4CodeGenerator.WritePropertiesForSingleType

foreach (IEdmProperty property in properties.Where(i => i.PropertyKind == EdmPropertyKind.Navigation
    && context.ExcludedSchemaTypes.Contains(i.Type.Definition.AsElementType().FullTypeName()) == false))

ODataT4CodeGenerator.WritePropertiesForStructuredType
var propertyInfos = properties.Where(property => context.ExcludedSchemaTypes.Contains(property.Type.Definition.AsElementType().FullTypeName()) == false)

Don't know if this is the way to go but it worked for us.

@lucacivale lucacivale added the Feature New feature label Jul 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature New feature
Projects
None yet
Development

No branches or pull requests

1 participant