Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Microsoft.AspNetCore.OData.Query;
using Microsoft.OData.Edm;
using Microsoft.OData.ModelBuilder;
using System;
using System.Collections.Generic;
using System.Globalization;
Expand Down Expand Up @@ -125,12 +126,12 @@ private HashSet<string> GetNavigationProperties(Type type)
IEdmEntityType entityType = context.Model.SchemaElements.OfType<IEdmEntityType>()
.SingleOrDefault(e => GetClrTypeFromEntityType(e).FullName == type.FullName);
if (entityType != null)
return entityType.NavigationProperties().Select(p => p.Name).ToHashSet();
return entityType.NavigationProperties().Select(GetNavigationPropertyName).ToHashSet();

IEdmComplexType complexType = context.Model.SchemaElements.OfType<IEdmComplexType>()
.SingleOrDefault(e => GetClrTypeFromComplexType(e).FullName == type.FullName);
if (complexType != null)
return complexType.NavigationProperties().Select(p => p.Name).ToHashSet();
return complexType.NavigationProperties().Select(GetNavigationPropertyName).ToHashSet();

return [];

Expand All @@ -139,6 +140,14 @@ Type GetClrTypeFromEntityType(IEdmEntityType entityType)

Type GetClrTypeFromComplexType(IEdmComplexType complexType)
=> TypeExtensions.GetClrType(new EdmComplexTypeReference(complexType, true), context.Model, TypeExtensions.GetEdmToClrTypeMappings());

// Look up the name of the corresponding C# property, which may differ from the property name
// used in the EDM model, e.g. because the EnableLowerCamelCase option is being used.
string GetNavigationPropertyName(IEdmNavigationProperty prop)
{
var annotation = context.Model.GetAnnotationValue<ClrPropertyInfoAnnotation>(prop);
return annotation?.ClrPropertyInfo?.Name ?? prop.Name;
}
}
}
}
2 changes: 2 additions & 0 deletions AutoMapper.OData.EF6.Tests/GetTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,8 @@ public static ODataQueryOptions<T> GetODataQueryOptions<T>(string queryString, I
if (customNamespace != null)
builder.Namespace = customNamespace;

builder.EnableLowerCamelCase();

builder.EntitySet<T>(typeof(T).Name);
IEdmModel model = builder.GetEdmModel();
IEdmEntitySet entitySet = model.EntityContainer.FindEntitySet(typeof(T).Name);
Expand Down
4 changes: 4 additions & 0 deletions AutoMapper.OData.EFCore.Tests/GetTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,8 @@ public static ODataQueryOptions<T> GetODataQueryOptions<T>(string queryString, I
if (customNamespace != null)
builder.Namespace = customNamespace;

builder.EnableLowerCamelCase();

builder.EntitySet<T>(typeof(T).Name);
IEdmModel model = builder.GetEdmModel();
IEdmEntitySet entitySet = model.EntityContainer.FindEntitySet(typeof(T).Name);
Expand All @@ -706,6 +708,8 @@ public static ODataQueryOptions<T> GetODataQueryOptions<T>(string queryString, I
if (customNamespace != null)
builder.Namespace = customNamespace;

builder.EnableLowerCamelCase();

builder.EntitySet<X.CategoryModel>(typeof(X.CategoryModel).Name + "X");
builder.EntitySet<Model.CategoryModel>(nameof(Model.CategoryModel));
IEdmModel model = builder.GetEdmModel();
Expand Down
4 changes: 4 additions & 0 deletions ExpressionBuilder.Tests/ODataHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ private static IEdmModel GetModel<T>() where T : class

IEdmModel GetModel(ODataConventionModelBuilder builder)
{
builder.EnableLowerCamelCase();
builder.EntitySet<T>(modelType.Name);
if (modelType == typeof(Product))
{
Expand All @@ -51,6 +52,7 @@ public static SelectExpandClause GetSelectExpandClause<T>(IDictionary<string, st
entitySet,
queryOptions
);
parser.Resolver = new ODataUriResolver { EnableCaseInsensitive = true };

return parser.ParseSelectAndExpand();
}
Expand All @@ -75,6 +77,7 @@ public static FilterClause GetFilterClause<T>(IDictionary<string, string> queryO
entitySet,
queryOptions
);
parser.Resolver = new ODataUriResolver { EnableCaseInsensitive = true };

if (useFilterOption)
{
Expand Down Expand Up @@ -108,6 +111,7 @@ public static ODataQueryContext GetODataQueryContext<T>() where T : class
public static ODataQueryOptions<T> GetODataQueryOptions<T>(string queryString, IServiceProvider serviceProvider, IRouteBuilder routeBuilder) where T : class
{
ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
builder.EnableLowerCamelCase();

builder.EntitySet<T>(typeof(T).Name);
IEdmModel model = builder.GetEdmModel();
Expand Down
1 change: 1 addition & 0 deletions WebAPI.OData.EF6/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ private IEdmModel GetEdmModel()
{
var builder = new ODataConventionModelBuilder();
//builder.Namespace = "com.FooBar";
builder.EnableLowerCamelCase();
builder.EntitySet<OpsTenant>(nameof(OpsTenant));
builder.EntitySet<CoreBuilding>(nameof(CoreBuilding));
builder.EntitySet<OpsBuilder>(nameof(OpsBuilder));
Expand Down
1 change: 1 addition & 0 deletions WebAPI.OData.EFCore/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
private IEdmModel GetEdmModel()
{
var builder = new ODataConventionModelBuilder();
builder.EnableLowerCamelCase();
//builder.Namespace = "com.FooBar";
builder.EntitySet<OpsTenant>(nameof(OpsTenant));
builder.EntitySet<CoreBuilding>(nameof(CoreBuilding));
Expand Down