Skip to content

Commit

Permalink
Fix for Issue #230. ArgumentException: Member does not exist. (#231)
Browse files Browse the repository at this point in the history
  • Loading branch information
BlaiseD authored Jan 5, 2025
1 parent 54a8c4e commit b924cd8
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 8 deletions.
3 changes: 1 addition & 2 deletions AutoMapper.AspNetCore.OData.EFCore/LinqExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -591,8 +591,7 @@ private static List<List<ODataExpansionOptions>> GetExpansions(this IEnumerable<
(
expansions =>
{
segmentExpansions.Reverse();
segmentExpansions.ForEach(exp => expansions.Insert(0, exp));
expansions.InsertRange(0, segmentExpansions);
return expansions;
}
).ToList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,9 +314,15 @@ public static void SeedDatabase(AirVinylDbContext context)
new DoorManufacturer { Name = "Ikea" },
new DoorManufacturer { Name = "Hardwood" }
);
context.DoorKnobs.AddRange(
new DoorKnob { Style = "Circular" },
new DoorKnob { Style = "Lever" }
);

context.SaveChanges();

ICollection<DoorManufacturer> doorManufacturers = [.. context.DoorManufacturers];
ICollection<DoorKnob> doorKnobs = [.. context.DoorKnobs];

context.RecordStores.AddRange(
new SpecializedRecordStore()
Expand All @@ -335,8 +341,8 @@ public static void SeedDatabase(AirVinylDbContext context)
RoomNumbers = [3, 4, 5, 6],
Doors =
[
new() { Name = "Front Door", DoorManufacturerId = doorManufacturers.Single(m => m.Name == "Serta").Id },
new() { Name = "Side Door", DoorManufacturerId = doorManufacturers.Single(m => m.Name == "Hardwood").Id }
new() { Name = "Front Door", DoorManufacturerId = doorManufacturers.Single(m => m.Name == "Serta").Id, DoorKnobId = doorKnobs.Single(k => k.Style == "Circular").Id },
new() { Name = "Side Door", DoorManufacturerId = doorManufacturers.Single(m => m.Name == "Hardwood").Id, DoorKnobId = doorKnobs.Single(k => k.Style == "Lever").Id }
]
}
},
Expand All @@ -356,8 +362,8 @@ public static void SeedDatabase(AirVinylDbContext context)
RoomNumbers = [2, 3, 4, 5],
Doors =
[
new() { Name = "Main Door", DoorManufacturerId = doorManufacturers.Single(m => m.Name == "Serta").Id },
new() { Name = "Cabinet Door", DoorManufacturerId = doorManufacturers.Single(m => m.Name == "Serta").Id }
new() { Name = "Main Door", DoorManufacturerId = doorManufacturers.Single(m => m.Name == "Serta").Id, DoorKnobId = doorKnobs.Single(k => k.Style == "Circular").Id },
new() { Name = "Cabinet Door", DoorManufacturerId = doorManufacturers.Single(m => m.Name == "Serta").Id, DoorKnobId = doorKnobs.Single(k => k.Style == "Circular").Id}
]
}
},
Expand All @@ -376,8 +382,8 @@ public static void SeedDatabase(AirVinylDbContext context)
RoomNumbers = [1, 2, 3, 4],
Doors =
[
new() { Name = "Bedroom Door", DoorManufacturerId = doorManufacturers.Single(m => m.Name == "Serta").Id },
new() { Name = "Balcony Door", DoorManufacturerId = doorManufacturers.Single(m => m.Name == "Sealy").Id }
new() { Name = "Bedroom Door", DoorManufacturerId = doorManufacturers.Single(m => m.Name == "Serta").Id, DoorKnobId = doorKnobs.Single(k => k.Style == "Circular").Id },
new() { Name = "Balcony Door", DoorManufacturerId = doorManufacturers.Single(m => m.Name == "Sealy").Id, DoorKnobId = doorKnobs.Single(k => k.Style == "Lever").Id}
]
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class AirVinylDbContext : DbContext
public DbSet<Rating> Ratings { get; set; }
public DbSet<DynamicProperty> DynamicVinylRecordProperties { get; set; }
public DbSet<DoorManufacturer> DoorManufacturers { get; set; }
public DbSet<DoorKnob> DoorKnobs { get; set; }

public AirVinylDbContext(DbContextOptions<AirVinylDbContext> options)
: base(options)
Expand Down
2 changes: 2 additions & 0 deletions AutoMapper.OData.EFCore.Tests/AirVinylData/Door.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ public class Door
public string Name{ get; set; }
public int AddressId { get; set; }
public int DoorManufacturerId { get; set; }
public int DoorKnobId { get; set; }
public DoorManufacturer DoorManufacturer { get; set; }
public DoorKnob DoorKnob { get; set; }
}
}
11 changes: 11 additions & 0 deletions AutoMapper.OData.EFCore.Tests/AirVinylData/DoorKnob.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System.ComponentModel.DataAnnotations;

namespace AutoMapper.OData.EFCore.Tests.AirVinylData
{
public class DoorKnob
{
[Key]
public int Id { get; set; }
public string Style { get; set; }
}
}
11 changes: 11 additions & 0 deletions AutoMapper.OData.EFCore.Tests/AirVinylModel/DoorKnobModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System.ComponentModel.DataAnnotations;

namespace AutoMapper.OData.EFCore.Tests.AirVinylModel
{
public class DoorKnobModel
{
[Key]
public int Id { get; set; }
public string Style { get; set; }
}
}
2 changes: 2 additions & 0 deletions AutoMapper.OData.EFCore.Tests/AirVinylModel/DoorModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ public class DoorModel
public string Name { get; set; }
public int AddressId { get; set; }
public int DoorManufacturerId { get; set; }
public int DoorKnobId { get; set; }
public DoorManufacturerModel DoorManufacturer { get; set; }
public DoorKnobModel DoorKnob { get; set; }
}
}
21 changes: 21 additions & 0 deletions AutoMapper.OData.EFCore.Tests/ExpansionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,27 @@ static void Test(ICollection<RecordStoreModel> collection)
Assert.False(string.IsNullOrEmpty(collection.First().StoreAddress.Doors.First().Name));
Assert.NotNull(collection.First().StoreAddress.Doors.First().DoorManufacturer);
Assert.False(string.IsNullOrEmpty(collection.First().StoreAddress.Doors.First().DoorManufacturer.Name));
Assert.Null(collection.First().StoreAddress.Doors.First().DoorKnob);
}
}

[Fact]
public async Task GetRecordStoresCanExpandMultipleNavigationPropertiesOfNavigationPropertyUnderComplexType()
{
string query = "/recordstoremodel?$expand=StoreAddress/Doors($expand=DoorManufacturer,DoorKnob)";
Test(await GetAsync<RecordStoreModel, RecordStore>(query));

static void Test(ICollection<RecordStoreModel> collection)
{
Assert.True(collection.Count > 0);
Assert.True(collection.All(r => r.Ratings.Count == 0));
Assert.False(string.IsNullOrEmpty(collection.First().StoreAddress.Country));
Assert.NotEmpty(collection.First().StoreAddress.Doors);
Assert.False(string.IsNullOrEmpty(collection.First().StoreAddress.Doors.First().Name));
Assert.NotNull(collection.First().StoreAddress.Doors.First().DoorManufacturer);
Assert.False(string.IsNullOrEmpty(collection.First().StoreAddress.Doors.First().DoorManufacturer.Name));
Assert.NotNull(collection.First().StoreAddress.Doors.First().DoorKnob);
Assert.False(string.IsNullOrEmpty(collection.First().StoreAddress.Doors.First().DoorKnob.Style));
}
}

Expand Down
2 changes: 2 additions & 0 deletions AutoMapper.OData.EFCore.Tests/Mappings/AirVinylMappings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ public AirVinylMappings()
.ForAllMembers(o => o.ExplicitExpansion());
CreateMap<Car, CarModel>()
.ForAllMembers(o => o.ExplicitExpansion());
CreateMap<DoorKnob, DoorKnobModel>()
.ForAllMembers(o => o.ExplicitExpansion());
CreateMap<Door, DoorModel>()
.ForAllMembers(o => o.ExplicitExpansion());
CreateMap<DoorManufacturer, DoorManufacturerModel>()
Expand Down

0 comments on commit b924cd8

Please sign in to comment.