Skip to content

Commit b924cd8

Browse files
authored
Fix for Issue #230. ArgumentException: Member does not exist. (#231)
1 parent 54a8c4e commit b924cd8

File tree

9 files changed

+63
-8
lines changed

9 files changed

+63
-8
lines changed

AutoMapper.AspNetCore.OData.EFCore/LinqExtensions.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -591,8 +591,7 @@ private static List<List<ODataExpansionOptions>> GetExpansions(this IEnumerable<
591591
(
592592
expansions =>
593593
{
594-
segmentExpansions.Reverse();
595-
segmentExpansions.ForEach(exp => expansions.Insert(0, exp));
594+
expansions.InsertRange(0, segmentExpansions);
596595
return expansions;
597596
}
598597
).ToList();

AutoMapper.OData.EFCore.Tests/AirVinylData/AirVinylDatabaseInitializer.cs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -314,9 +314,15 @@ public static void SeedDatabase(AirVinylDbContext context)
314314
new DoorManufacturer { Name = "Ikea" },
315315
new DoorManufacturer { Name = "Hardwood" }
316316
);
317+
context.DoorKnobs.AddRange(
318+
new DoorKnob { Style = "Circular" },
319+
new DoorKnob { Style = "Lever" }
320+
);
321+
317322
context.SaveChanges();
318323

319324
ICollection<DoorManufacturer> doorManufacturers = [.. context.DoorManufacturers];
325+
ICollection<DoorKnob> doorKnobs = [.. context.DoorKnobs];
320326

321327
context.RecordStores.AddRange(
322328
new SpecializedRecordStore()
@@ -335,8 +341,8 @@ public static void SeedDatabase(AirVinylDbContext context)
335341
RoomNumbers = [3, 4, 5, 6],
336342
Doors =
337343
[
338-
new() { Name = "Front Door", DoorManufacturerId = doorManufacturers.Single(m => m.Name == "Serta").Id },
339-
new() { Name = "Side Door", DoorManufacturerId = doorManufacturers.Single(m => m.Name == "Hardwood").Id }
344+
new() { Name = "Front Door", DoorManufacturerId = doorManufacturers.Single(m => m.Name == "Serta").Id, DoorKnobId = doorKnobs.Single(k => k.Style == "Circular").Id },
345+
new() { Name = "Side Door", DoorManufacturerId = doorManufacturers.Single(m => m.Name == "Hardwood").Id, DoorKnobId = doorKnobs.Single(k => k.Style == "Lever").Id }
340346
]
341347
}
342348
},
@@ -356,8 +362,8 @@ public static void SeedDatabase(AirVinylDbContext context)
356362
RoomNumbers = [2, 3, 4, 5],
357363
Doors =
358364
[
359-
new() { Name = "Main Door", DoorManufacturerId = doorManufacturers.Single(m => m.Name == "Serta").Id },
360-
new() { Name = "Cabinet Door", DoorManufacturerId = doorManufacturers.Single(m => m.Name == "Serta").Id }
365+
new() { Name = "Main Door", DoorManufacturerId = doorManufacturers.Single(m => m.Name == "Serta").Id, DoorKnobId = doorKnobs.Single(k => k.Style == "Circular").Id },
366+
new() { Name = "Cabinet Door", DoorManufacturerId = doorManufacturers.Single(m => m.Name == "Serta").Id, DoorKnobId = doorKnobs.Single(k => k.Style == "Circular").Id}
361367
]
362368
}
363369
},
@@ -376,8 +382,8 @@ public static void SeedDatabase(AirVinylDbContext context)
376382
RoomNumbers = [1, 2, 3, 4],
377383
Doors =
378384
[
379-
new() { Name = "Bedroom Door", DoorManufacturerId = doorManufacturers.Single(m => m.Name == "Serta").Id },
380-
new() { Name = "Balcony Door", DoorManufacturerId = doorManufacturers.Single(m => m.Name == "Sealy").Id }
385+
new() { Name = "Bedroom Door", DoorManufacturerId = doorManufacturers.Single(m => m.Name == "Serta").Id, DoorKnobId = doorKnobs.Single(k => k.Style == "Circular").Id },
386+
new() { Name = "Balcony Door", DoorManufacturerId = doorManufacturers.Single(m => m.Name == "Sealy").Id, DoorKnobId = doorKnobs.Single(k => k.Style == "Lever").Id}
381387
]
382388
}
383389
}

AutoMapper.OData.EFCore.Tests/AirVinylData/AirVinylDbContext.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public class AirVinylDbContext : DbContext
1212
public DbSet<Rating> Ratings { get; set; }
1313
public DbSet<DynamicProperty> DynamicVinylRecordProperties { get; set; }
1414
public DbSet<DoorManufacturer> DoorManufacturers { get; set; }
15+
public DbSet<DoorKnob> DoorKnobs { get; set; }
1516

1617
public AirVinylDbContext(DbContextOptions<AirVinylDbContext> options)
1718
: base(options)

AutoMapper.OData.EFCore.Tests/AirVinylData/Door.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ public class Door
99
public string Name{ get; set; }
1010
public int AddressId { get; set; }
1111
public int DoorManufacturerId { get; set; }
12+
public int DoorKnobId { get; set; }
1213
public DoorManufacturer DoorManufacturer { get; set; }
14+
public DoorKnob DoorKnob { get; set; }
1315
}
1416
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System.ComponentModel.DataAnnotations;
2+
3+
namespace AutoMapper.OData.EFCore.Tests.AirVinylData
4+
{
5+
public class DoorKnob
6+
{
7+
[Key]
8+
public int Id { get; set; }
9+
public string Style { get; set; }
10+
}
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System.ComponentModel.DataAnnotations;
2+
3+
namespace AutoMapper.OData.EFCore.Tests.AirVinylModel
4+
{
5+
public class DoorKnobModel
6+
{
7+
[Key]
8+
public int Id { get; set; }
9+
public string Style { get; set; }
10+
}
11+
}

AutoMapper.OData.EFCore.Tests/AirVinylModel/DoorModel.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ public class DoorModel
99
public string Name { get; set; }
1010
public int AddressId { get; set; }
1111
public int DoorManufacturerId { get; set; }
12+
public int DoorKnobId { get; set; }
1213
public DoorManufacturerModel DoorManufacturer { get; set; }
14+
public DoorKnobModel DoorKnob { get; set; }
1315
}
1416
}

AutoMapper.OData.EFCore.Tests/ExpansionTests.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,27 @@ static void Test(ICollection<RecordStoreModel> collection)
8989
Assert.False(string.IsNullOrEmpty(collection.First().StoreAddress.Doors.First().Name));
9090
Assert.NotNull(collection.First().StoreAddress.Doors.First().DoorManufacturer);
9191
Assert.False(string.IsNullOrEmpty(collection.First().StoreAddress.Doors.First().DoorManufacturer.Name));
92+
Assert.Null(collection.First().StoreAddress.Doors.First().DoorKnob);
93+
}
94+
}
95+
96+
[Fact]
97+
public async Task GetRecordStoresCanExpandMultipleNavigationPropertiesOfNavigationPropertyUnderComplexType()
98+
{
99+
string query = "/recordstoremodel?$expand=StoreAddress/Doors($expand=DoorManufacturer,DoorKnob)";
100+
Test(await GetAsync<RecordStoreModel, RecordStore>(query));
101+
102+
static void Test(ICollection<RecordStoreModel> collection)
103+
{
104+
Assert.True(collection.Count > 0);
105+
Assert.True(collection.All(r => r.Ratings.Count == 0));
106+
Assert.False(string.IsNullOrEmpty(collection.First().StoreAddress.Country));
107+
Assert.NotEmpty(collection.First().StoreAddress.Doors);
108+
Assert.False(string.IsNullOrEmpty(collection.First().StoreAddress.Doors.First().Name));
109+
Assert.NotNull(collection.First().StoreAddress.Doors.First().DoorManufacturer);
110+
Assert.False(string.IsNullOrEmpty(collection.First().StoreAddress.Doors.First().DoorManufacturer.Name));
111+
Assert.NotNull(collection.First().StoreAddress.Doors.First().DoorKnob);
112+
Assert.False(string.IsNullOrEmpty(collection.First().StoreAddress.Doors.First().DoorKnob.Style));
92113
}
93114
}
94115

AutoMapper.OData.EFCore.Tests/Mappings/AirVinylMappings.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ public AirVinylMappings()
1111
.ForAllMembers(o => o.ExplicitExpansion());
1212
CreateMap<Car, CarModel>()
1313
.ForAllMembers(o => o.ExplicitExpansion());
14+
CreateMap<DoorKnob, DoorKnobModel>()
15+
.ForAllMembers(o => o.ExplicitExpansion());
1416
CreateMap<Door, DoorModel>()
1517
.ForAllMembers(o => o.ExplicitExpansion());
1618
CreateMap<DoorManufacturer, DoorManufacturerModel>()

0 commit comments

Comments
 (0)