From f686c16b42b4bf364321decabdb27cd618ed33a5 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Tue, 29 Oct 2024 13:18:14 +1100 Subject: [PATCH 1/2] . --- .../CustomOrder/CustomOrderChildEntity.cs | 6 ++ .../CustomOrder/CustomOrderChildGraphType.cs | 7 +++ .../CustomOrder/CustomOrderParentEntity.cs | 5 ++ .../CustomOrder/CustomOrderParentGraphType.cs | 17 ++++++ .../IntegrationTests.CustomOrder.verified.txt | 60 +++++++++++++++++++ .../IntegrationTests.SchemaPrint.verified.txt | 13 ++++ .../IntegrationTests/IntegrationTests.cs | 38 ++++++++++++ src/Tests/IntegrationTests/MyDataContext.cs | 4 ++ src/Tests/IntegrationTests/Query.cs | 4 ++ src/Tests/IntegrationTests/Schema.cs | 2 + 10 files changed, 156 insertions(+) create mode 100644 src/Tests/IntegrationTests/Graphs/CustomOrder/CustomOrderChildEntity.cs create mode 100644 src/Tests/IntegrationTests/Graphs/CustomOrder/CustomOrderChildGraphType.cs create mode 100644 src/Tests/IntegrationTests/Graphs/CustomOrder/CustomOrderParentEntity.cs create mode 100644 src/Tests/IntegrationTests/Graphs/CustomOrder/CustomOrderParentGraphType.cs create mode 100644 src/Tests/IntegrationTests/IntegrationTests.CustomOrder.verified.txt diff --git a/src/Tests/IntegrationTests/Graphs/CustomOrder/CustomOrderChildEntity.cs b/src/Tests/IntegrationTests/Graphs/CustomOrder/CustomOrderChildEntity.cs new file mode 100644 index 000000000..8810ac7c6 --- /dev/null +++ b/src/Tests/IntegrationTests/Graphs/CustomOrder/CustomOrderChildEntity.cs @@ -0,0 +1,6 @@ +public class CustomOrderChildEntity +{ + public Guid Id { get; set; } = Guid.NewGuid(); + public Guid? ParentId { get; set; } + public CustomOrderParentEntity? Parent { get; set; } +} \ No newline at end of file diff --git a/src/Tests/IntegrationTests/Graphs/CustomOrder/CustomOrderChildGraphType.cs b/src/Tests/IntegrationTests/Graphs/CustomOrder/CustomOrderChildGraphType.cs new file mode 100644 index 000000000..14abba9fb --- /dev/null +++ b/src/Tests/IntegrationTests/Graphs/CustomOrder/CustomOrderChildGraphType.cs @@ -0,0 +1,7 @@ +public class CustomOrderChildGraphType : + EfObjectGraphType +{ + public CustomOrderChildGraphType(IEfGraphQLService graphQlService) : + base(graphQlService) => + AutoMap(); +} \ No newline at end of file diff --git a/src/Tests/IntegrationTests/Graphs/CustomOrder/CustomOrderParentEntity.cs b/src/Tests/IntegrationTests/Graphs/CustomOrder/CustomOrderParentEntity.cs new file mode 100644 index 000000000..91ce09157 --- /dev/null +++ b/src/Tests/IntegrationTests/Graphs/CustomOrder/CustomOrderParentEntity.cs @@ -0,0 +1,5 @@ +public class CustomOrderParentEntity +{ + public Guid Id { get; set; } = Guid.NewGuid(); + public IList Children { get; set; } = []; +} \ No newline at end of file diff --git a/src/Tests/IntegrationTests/Graphs/CustomOrder/CustomOrderParentGraphType.cs b/src/Tests/IntegrationTests/Graphs/CustomOrder/CustomOrderParentGraphType.cs new file mode 100644 index 000000000..492ad9802 --- /dev/null +++ b/src/Tests/IntegrationTests/Graphs/CustomOrder/CustomOrderParentGraphType.cs @@ -0,0 +1,17 @@ +public class CustomOrderParentGraphType : + EfObjectGraphType +{ + public CustomOrderParentGraphType(IEfGraphQLService graphQlService) : + base(graphQlService) + { + AddQueryField( + name: "customOrderChildren", + resolve: context => + { + var parentId = context.Source.Id; + return context.DbContext.CustomOrderChildEntities + .Where(_ => _.ParentId == parentId); + }); + AutoMap(); + } +} \ No newline at end of file diff --git a/src/Tests/IntegrationTests/IntegrationTests.CustomOrder.verified.txt b/src/Tests/IntegrationTests/IntegrationTests.CustomOrder.verified.txt new file mode 100644 index 000000000..ba1e2d8fb --- /dev/null +++ b/src/Tests/IntegrationTests/IntegrationTests.CustomOrder.verified.txt @@ -0,0 +1,60 @@ +{ + target: +{ + "data": { + "customOrder": [ + { + "customOrderChildren": [ + { + "id": "Guid_1" + }, + { + "id": "Guid_2" + } + ] + }, + { + "customOrderChildren": [ + { + "id": "Guid_3" + } + ] + } + ] + } +}, + sql: [ + { + Text: +SELECT [c].[Id] +FROM [CustomOrderParentEntities] AS [c], + HasTransaction: false + }, + { + Text: +SELECT [c].[Id], [c].[ParentId] +FROM [CustomOrderChildEntities] AS [c] +WHERE [c].[ParentId] = @__parentId_0, + Parameters: { + @__parentId_0: { + Value: Guid_4, + IsNullable: true + } + }, + HasTransaction: false + }, + { + Text: +SELECT [c].[Id], [c].[ParentId] +FROM [CustomOrderChildEntities] AS [c] +WHERE [c].[ParentId] = @__parentId_0, + Parameters: { + @__parentId_0: { + Value: Guid_5, + IsNullable: true + } + }, + HasTransaction: false + } + ] +} \ No newline at end of file diff --git a/src/Tests/IntegrationTests/IntegrationTests.SchemaPrint.verified.txt b/src/Tests/IntegrationTests/IntegrationTests.SchemaPrint.verified.txt index 335500252..4197d00e5 100644 --- a/src/Tests/IntegrationTests/IntegrationTests.SchemaPrint.verified.txt +++ b/src/Tests/IntegrationTests/IntegrationTests.SchemaPrint.verified.txt @@ -7,6 +7,7 @@ withNullableEntities(id: ID, ids: [ID!], where: [WhereExpression!], orderBy: [OrderBy!], skip: Int, take: Int): [WithNullable!]! namedEntities(id: ID, ids: [ID!], where: [WhereExpression!], orderBy: [OrderBy!], skip: Int, take: Int): [NamedId!]! misNamed(id: ID, ids: [ID!], where: [WhereExpression!], orderBy: [OrderBy!], skip: Int, take: Int): [WithMisNamedQueryParent!]! + customOrder(id: ID, ids: [ID!], where: [WhereExpression!], orderBy: [OrderBy!], skip: Int, take: Int): [CustomOrderParent!]! parentEntities(id: ID, ids: [ID!], where: [WhereExpression!], orderBy: [OrderBy!], skip: Int, take: Int): [Parent!]! childEntities(id: ID, ids: [ID!], where: [WhereExpression!], orderBy: [OrderBy!], skip: Int, take: Int): [Child!]! dateEntities(id: ID, ids: [ID!], where: [WhereExpression!], orderBy: [OrderBy!], skip: Int, take: Int): [DateEntity!]! @@ -219,6 +220,18 @@ type WithMisNamedQueryChild { parentId: ID } +type CustomOrderParent { + customOrderChildren(id: ID, ids: [ID!], where: [WhereExpression!], orderBy: [OrderBy!], skip: Int, take: Int): [CustomOrderChild!]! + children(id: ID, ids: [ID!], where: [WhereExpression!], orderBy: [OrderBy!], skip: Int, take: Int): [CustomOrderChild!]! + id: ID! +} + +type CustomOrderChild { + parent: CustomOrderParent + id: ID! + parentId: ID +} + type Parent { childrenConnection( "Only return edges after the specified cursor." diff --git a/src/Tests/IntegrationTests/IntegrationTests.cs b/src/Tests/IntegrationTests/IntegrationTests.cs index c6858e723..07db33774 100644 --- a/src/Tests/IntegrationTests/IntegrationTests.cs +++ b/src/Tests/IntegrationTests/IntegrationTests.cs @@ -2514,6 +2514,44 @@ public async Task MisNamedQuery() await RunQuery(database, query, null, null, false, [entity1, entity2, entity3, entity4, entity5]); } + [Fact] + public async Task CustomOrder() + { + var query = + """ + { + customOrder + { + customOrderChildren + { + id + } + } + } + """; + + var entity1 = new CustomOrderParentEntity(); + var entity2 = new CustomOrderChildEntity + { + Parent = entity1 + }; + var entity3 = new CustomOrderChildEntity + { + Parent = entity1 + }; + entity1.Children.Add(entity2); + entity1.Children.Add(entity3); + var entity4 = new CustomOrderParentEntity(); + var entity5 = new CustomOrderChildEntity + { + Parent = entity4 + }; + entity4.Children.Add(entity5); + + await using var database = await sqlInstance.Build(); + await RunQuery(database, query, null, null, false, [entity1, entity2, entity3, entity4, entity5]); + } + [Fact(Skip = "fix order")] public async Task Parent_child() { diff --git a/src/Tests/IntegrationTests/MyDataContext.cs b/src/Tests/IntegrationTests/MyDataContext.cs index ffc8d4d84..404541168 100644 --- a/src/Tests/IntegrationTests/MyDataContext.cs +++ b/src/Tests/IntegrationTests/MyDataContext.cs @@ -8,6 +8,8 @@ public class IntegrationDbContext(DbContextOptions options) : public DbSet FilterParentEntities { get; set; } = null!; public DbSet FilterChildEntities { get; set; } = null!; public DbSet ChildEntities { get; set; } = null!; + public DbSet CustomOrderChildEntities { get; set; } = null!; + public DbSet CustomOrderParentEntities { get; set; } = null!; public DbSet WithMisNamedQueryChildEntities { get; set; } = null!; public DbSet WithMisNamedQueryParentEntities { get; set; } = null!; public DbSet Level1Entities { get; set; } = null!; @@ -44,6 +46,8 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) modelBuilder.Entity(); modelBuilder.Entity(); modelBuilder.Entity(); + modelBuilder.Entity(); + modelBuilder.Entity(); modelBuilder.Entity(); modelBuilder.Entity() .HasOne(_ => _.IncludeNonQueryableB) diff --git a/src/Tests/IntegrationTests/Query.cs b/src/Tests/IntegrationTests/Query.cs index 66474f5bd..e962c7f19 100644 --- a/src/Tests/IntegrationTests/Query.cs +++ b/src/Tests/IntegrationTests/Query.cs @@ -44,6 +44,10 @@ public Query(IEfGraphQLService efGraphQlService) name: "misNamed", resolve: _ => _.DbContext.WithMisNamedQueryParentEntities); + AddQueryField( + name: "customOrder", + resolve: _ => _.DbContext.CustomOrderParentEntities); + AddQueryField( name: "parentEntities", resolve: _ => _.DbContext.ParentEntities); diff --git a/src/Tests/IntegrationTests/Schema.cs b/src/Tests/IntegrationTests/Schema.cs index 53aaadcad..314c7dd42 100644 --- a/src/Tests/IntegrationTests/Schema.cs +++ b/src/Tests/IntegrationTests/Schema.cs @@ -25,6 +25,8 @@ public Schema(IServiceProvider resolver) : RegisterTypeMapping(typeof(WithMisNamedQueryChildEntity), typeof(WithMisNamedQueryChildGraphType)); RegisterTypeMapping(typeof(WithNullableEntity), typeof(WithNullableGraphType)); RegisterTypeMapping(typeof(NamedIdEntity), typeof(NamedIdGraphType)); + RegisterTypeMapping(typeof(CustomOrderParentEntity), typeof(CustomOrderParentGraphType)); + RegisterTypeMapping(typeof(CustomOrderChildEntity), typeof(CustomOrderChildGraphType)); RegisterTypeMapping(typeof(DerivedEntity), typeof(DerivedGraphType)); RegisterTypeMapping(typeof(DerivedWithNavigationEntity), typeof(DerivedWithNavigationGraphType)); RegisterTypeMapping(typeof(DerivedChildEntity), typeof(DerivedChildGraphType)); From e6a2dec424617234956492d4678088a306d40a6e Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Tue, 29 Oct 2024 13:52:39 +1100 Subject: [PATCH 2/2] add orderby callback --- src/Directory.Build.props | 2 +- .../GraphApi/EfGraphQLService_Queryable.cs | 18 +++++++++++++----- .../GraphApi/EfInterfaceGraphType.cs | 5 +++-- .../GraphApi/EfObjectGraphType.cs | 5 +++-- .../GraphApi/IEfGraphQLService_Queryable.cs | 6 ++++-- .../GraphApi/QueryGraphType.cs | 5 +++-- .../CustomOrder/CustomOrderChildEntity.cs | 1 + .../CustomOrder/CustomOrderParentGraphType.cs | 6 ++++-- .../IntegrationTests.CustomOrder.verified.txt | 19 ++++++++++++------- .../IntegrationTests.SchemaPrint.verified.txt | 1 + .../IntegrationTests/IntegrationTests.cs | 12 ++++++++---- 11 files changed, 53 insertions(+), 27 deletions(-) diff --git a/src/Directory.Build.props b/src/Directory.Build.props index 243eb9932..40b81c247 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -2,7 +2,7 @@ CS1591;NU5104;CS1573;CS9107 - 27.2.2 + 28.0.0-beta.1 preview 1.0.0 EntityFrameworkCore, EntityFramework, GraphQL diff --git a/src/GraphQL.EntityFramework/GraphApi/EfGraphQLService_Queryable.cs b/src/GraphQL.EntityFramework/GraphApi/EfGraphQLService_Queryable.cs index a091f9268..ce5887b65 100644 --- a/src/GraphQL.EntityFramework/GraphApi/EfGraphQLService_Queryable.cs +++ b/src/GraphQL.EntityFramework/GraphApi/EfGraphQLService_Queryable.cs @@ -8,10 +8,11 @@ public FieldBuilder AddQueryField( string name, Func, IQueryable>? resolve = null, Type? graphType = null, - bool omitQueryArguments = false) + bool omitQueryArguments = false, + Func, IQueryable, IOrderedQueryable>? orderBy = null) where TReturn : class { - var field = BuildQueryField(graphType, name, resolve, omitQueryArguments); + var field = BuildQueryField(graphType, name, resolve, omitQueryArguments, orderBy); graph.AddField(field); return new FieldBuilderEx(field); } @@ -21,10 +22,11 @@ public FieldBuilder AddQueryField( string name, Func, IQueryable>? resolve = null, Type? itemGraphType = null, - bool omitQueryArguments = false) + bool omitQueryArguments = false, + Func, IQueryable, IOrderedQueryable>? orderBy = null) where TReturn : class { - var field = BuildQueryField(itemGraphType, name, resolve, omitQueryArguments); + var field = BuildQueryField(itemGraphType, name, resolve, omitQueryArguments, orderBy); graph.AddField(field); return new FieldBuilderEx(field); } @@ -33,7 +35,8 @@ FieldType BuildQueryField( Type? itemGraphType, string name, Func, IQueryable>? resolve, - bool omitQueryArguments) + bool omitQueryArguments, + Func, IQueryable, IOrderedQueryable>? orderBy) where TReturn : class { Guard.AgainstWhiteSpace(nameof(name), name); @@ -65,6 +68,11 @@ FieldType BuildQueryField( query = query.ApplyGraphQlArguments(context, names, true, omitQueryArguments); } + if(orderBy is not null) + { + query = orderBy(fieldContext, query); + } + QueryLogger.Write(query); List list; diff --git a/src/GraphQL.EntityFramework/GraphApi/EfInterfaceGraphType.cs b/src/GraphQL.EntityFramework/GraphApi/EfInterfaceGraphType.cs index 7753617af..6211623c5 100644 --- a/src/GraphQL.EntityFramework/GraphApi/EfInterfaceGraphType.cs +++ b/src/GraphQL.EntityFramework/GraphApi/EfInterfaceGraphType.cs @@ -38,9 +38,10 @@ public ConnectionBuilder AddQueryConnectionField( public FieldBuilder AddQueryField( string name, Type? graphType = null, - bool omitQueryArguments = false) + bool omitQueryArguments = false, + Func, IQueryable, IOrderedQueryable>? orderBy = null) where TReturn : class => - GraphQlService.AddQueryField(this, name, null, graphType, omitQueryArguments); + GraphQlService.AddQueryField(this, name, null, graphType, omitQueryArguments, orderBy); public TDbContext ResolveDbContext(IResolveFieldContext context) => GraphQlService.ResolveDbContext(context); diff --git a/src/GraphQL.EntityFramework/GraphApi/EfObjectGraphType.cs b/src/GraphQL.EntityFramework/GraphApi/EfObjectGraphType.cs index 260bf221f..28edc8991 100644 --- a/src/GraphQL.EntityFramework/GraphApi/EfObjectGraphType.cs +++ b/src/GraphQL.EntityFramework/GraphApi/EfObjectGraphType.cs @@ -54,9 +54,10 @@ public FieldBuilder AddQueryField( string name, Func, IQueryable> resolve, Type? graphType = null, - bool omitQueryArguments = false) + bool omitQueryArguments = false, + Func, IQueryable, IOrderedQueryable>? orderBy = null) where TReturn : class => - GraphQlService.AddQueryField(this, name, resolve, graphType, omitQueryArguments); + GraphQlService.AddQueryField(this, name, resolve, graphType, omitQueryArguments, orderBy); public TDbContext ResolveDbContext(IResolveFieldContext context) => GraphQlService.ResolveDbContext(context); diff --git a/src/GraphQL.EntityFramework/GraphApi/IEfGraphQLService_Queryable.cs b/src/GraphQL.EntityFramework/GraphApi/IEfGraphQLService_Queryable.cs index 5937e492b..9f0852314 100644 --- a/src/GraphQL.EntityFramework/GraphApi/IEfGraphQLService_Queryable.cs +++ b/src/GraphQL.EntityFramework/GraphApi/IEfGraphQLService_Queryable.cs @@ -7,7 +7,8 @@ FieldBuilder AddQueryField( string name, Func, IQueryable>? resolve = null, Type? itemGraphType = null, - bool omitQueryArguments = false) + bool omitQueryArguments = false, + Func, IQueryable, IOrderedQueryable>? orderBy = null) where TReturn : class; FieldBuilder AddQueryField( @@ -15,6 +16,7 @@ FieldBuilder AddQueryField( string name, Func, IQueryable>? resolve = null, Type? itemGraphType = null, - bool omitQueryArguments = false) + bool omitQueryArguments = false, + Func, IQueryable, IOrderedQueryable>? orderBy = null) where TReturn : class; } \ No newline at end of file diff --git a/src/GraphQL.EntityFramework/GraphApi/QueryGraphType.cs b/src/GraphQL.EntityFramework/GraphApi/QueryGraphType.cs index 64677a6a4..c808a5a6c 100644 --- a/src/GraphQL.EntityFramework/GraphApi/QueryGraphType.cs +++ b/src/GraphQL.EntityFramework/GraphApi/QueryGraphType.cs @@ -23,9 +23,10 @@ public FieldBuilder AddQueryField( string name, Func, IQueryable> resolve, Type? graphType = null, - bool omitQueryArguments = false) + bool omitQueryArguments = false, + Func, IQueryable, IOrderedQueryable>? orderBy = null) where TReturn : class => - GraphQlService.AddQueryField(this, name, resolve, graphType, omitQueryArguments); + GraphQlService.AddQueryField(this, name, resolve, graphType, omitQueryArguments, orderBy); public FieldBuilder AddSingleField( Func, IQueryable> resolve, diff --git a/src/Tests/IntegrationTests/Graphs/CustomOrder/CustomOrderChildEntity.cs b/src/Tests/IntegrationTests/Graphs/CustomOrder/CustomOrderChildEntity.cs index 8810ac7c6..c77f5b4b2 100644 --- a/src/Tests/IntegrationTests/Graphs/CustomOrder/CustomOrderChildEntity.cs +++ b/src/Tests/IntegrationTests/Graphs/CustomOrder/CustomOrderChildEntity.cs @@ -1,6 +1,7 @@ public class CustomOrderChildEntity { public Guid Id { get; set; } = Guid.NewGuid(); + public string? Property { get; set; } public Guid? ParentId { get; set; } public CustomOrderParentEntity? Parent { get; set; } } \ No newline at end of file diff --git a/src/Tests/IntegrationTests/Graphs/CustomOrder/CustomOrderParentGraphType.cs b/src/Tests/IntegrationTests/Graphs/CustomOrder/CustomOrderParentGraphType.cs index 492ad9802..b71e792df 100644 --- a/src/Tests/IntegrationTests/Graphs/CustomOrder/CustomOrderParentGraphType.cs +++ b/src/Tests/IntegrationTests/Graphs/CustomOrder/CustomOrderParentGraphType.cs @@ -1,7 +1,8 @@ public class CustomOrderParentGraphType : EfObjectGraphType { - public CustomOrderParentGraphType(IEfGraphQLService graphQlService) : + public CustomOrderParentGraphType(IEfGraphQLService graphQlService) + : base(graphQlService) { AddQueryField( @@ -11,7 +12,8 @@ public CustomOrderParentGraphType(IEfGraphQLService graphQ var parentId = context.Source.Id; return context.DbContext.CustomOrderChildEntities .Where(_ => _.ParentId == parentId); - }); + }, + orderBy: (context, query) => query.OrderBy(_ => _.Property)); AutoMap(); } } \ No newline at end of file diff --git a/src/Tests/IntegrationTests/IntegrationTests.CustomOrder.verified.txt b/src/Tests/IntegrationTests/IntegrationTests.CustomOrder.verified.txt index ba1e2d8fb..5b26a3e82 100644 --- a/src/Tests/IntegrationTests/IntegrationTests.CustomOrder.verified.txt +++ b/src/Tests/IntegrationTests/IntegrationTests.CustomOrder.verified.txt @@ -6,17 +6,20 @@ { "customOrderChildren": [ { - "id": "Guid_1" + "id": "Guid_1", + "property": "Value2" }, { - "id": "Guid_2" + "id": "Guid_2", + "property": "Value3" } ] }, { "customOrderChildren": [ { - "id": "Guid_3" + "id": "Guid_3", + "property": "Value5" } ] } @@ -32,9 +35,10 @@ FROM [CustomOrderParentEntities] AS [c], }, { Text: -SELECT [c].[Id], [c].[ParentId] +SELECT [c].[Id], [c].[ParentId], [c].[Property] FROM [CustomOrderChildEntities] AS [c] -WHERE [c].[ParentId] = @__parentId_0, +WHERE [c].[ParentId] = @__parentId_0 +ORDER BY [c].[Property], Parameters: { @__parentId_0: { Value: Guid_4, @@ -45,9 +49,10 @@ WHERE [c].[ParentId] = @__parentId_0, }, { Text: -SELECT [c].[Id], [c].[ParentId] +SELECT [c].[Id], [c].[ParentId], [c].[Property] FROM [CustomOrderChildEntities] AS [c] -WHERE [c].[ParentId] = @__parentId_0, +WHERE [c].[ParentId] = @__parentId_0 +ORDER BY [c].[Property], Parameters: { @__parentId_0: { Value: Guid_5, diff --git a/src/Tests/IntegrationTests/IntegrationTests.SchemaPrint.verified.txt b/src/Tests/IntegrationTests/IntegrationTests.SchemaPrint.verified.txt index 4197d00e5..266f38751 100644 --- a/src/Tests/IntegrationTests/IntegrationTests.SchemaPrint.verified.txt +++ b/src/Tests/IntegrationTests/IntegrationTests.SchemaPrint.verified.txt @@ -230,6 +230,7 @@ type CustomOrderChild { parent: CustomOrderParent id: ID! parentId: ID + property: String } type Parent { diff --git a/src/Tests/IntegrationTests/IntegrationTests.cs b/src/Tests/IntegrationTests/IntegrationTests.cs index 07db33774..33577a6bb 100644 --- a/src/Tests/IntegrationTests/IntegrationTests.cs +++ b/src/Tests/IntegrationTests/IntegrationTests.cs @@ -2524,7 +2524,8 @@ public async Task CustomOrder() { customOrderChildren { - id + id, + property } } } @@ -2533,18 +2534,21 @@ public async Task CustomOrder() var entity1 = new CustomOrderParentEntity(); var entity2 = new CustomOrderChildEntity { - Parent = entity1 + Parent = entity1, + Property = "Value2" }; var entity3 = new CustomOrderChildEntity { - Parent = entity1 + Parent = entity1, + Property = "Value3" }; entity1.Children.Add(entity2); entity1.Children.Add(entity3); var entity4 = new CustomOrderParentEntity(); var entity5 = new CustomOrderChildEntity { - Parent = entity4 + Parent = entity4, + Property = "Value5" }; entity4.Children.Add(entity5);