Skip to content

Commit

Permalink
Fix Implemented the suggested Odata.Bind EntitySet fix suggested on i…
Browse files Browse the repository at this point in the history
  • Loading branch information
Hannu Pakarinen authored and Hannu Pakarinen committed Jan 19, 2024
1 parent 91472bf commit 93786db
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,5 @@ nuget.exe
/paket-files
/.paket/paket.exe
/.paket/Paket.Restore.targets
/nuget.config
/src/CRMTester
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"sdk": {
"version": "7.0.100"
"version": "7.0.403"
}
}
25 changes: 24 additions & 1 deletion src/Simple.OData.Client.V4.Adapter/Metadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,12 @@ public override string GetLinkedCollectionName(string instanceTypeName, string t
return singleton.Name;
}

if (TryGetEntityType(instanceTypeName, out var entityType))
if (TryGetEntityType(instanceTypeName, out var entityType) && TryGetEntitySetByType(entityType.FullTypeName(), out entitySet))
{
return entitySet.Name;
}

if (TryGetEntityType(instanceTypeName, out entityType))
{
return entityType.Name;
}
Expand All @@ -122,6 +127,11 @@ public override string GetLinkedCollectionName(string instanceTypeName, string t
return entitySet.Name;
}

if (TryGetEntityType(typeName, out entityType) && TryGetEntitySetByType(entityType.FullTypeName(), out entitySet))
{
return entitySet.Name;
}

if (TryGetSingleton(typeName, out singleton))
{
isSingleton = true;
Expand Down Expand Up @@ -337,6 +347,19 @@ private bool TryGetEntitySet(string entitySetName, out IEdmEntitySet entitySet)
return entitySet != null;
}

private bool TryGetEntitySetByType(string entityType, out IEdmEntitySet entitySet)
{
if (entityType.Contains("/"))
entityType = entityType.Split('/').First();

entitySet = _model.SchemaElements
.Where(x => x.SchemaElementKind == EdmSchemaElementKind.EntityContainer)
.SelectMany(x => (x as IEdmEntityContainer).EntitySets())
.BestMatch(x => x.Type.AsElementType().FullTypeName(), entityType, NameMatchResolver);

return entitySet != null;
}

private IEnumerable<IEdmSingleton> GetSingletons()
{
return _model.SchemaElements
Expand Down

0 comments on commit 93786db

Please sign in to comment.