Comments (2)
@budt12 Since some concerns have been raised about the currently open PR, and discussions are ongoing, I want to suggest a workaround in the meantime. The workaround consists of providing a custom type resolver delegate to the ODataMessageWriterSettings.ClientCustomTypeResolver
property. The custom resolver can then implement custom logic to handle types that are not found in your model using the default (case-sensitive) IEdmModel.FindType
extension method.
Here's a sample implementation of such a custom resolver. It builds a static case-insensitive copy of the core schema types in the EdmCoreModel
. When a type is not found, it looks it up in this cache. Building the cache is a one-time cost. I opted to copy only the core model types in order to keep the cache small and because your use-case seems to be concerned only with EDM primitve types.
private static Dictionary<string, IEdmType> caseInsensitiveCoreTypesCache = BuildCaseInsensitiveCoreTypesCache();
public static IEdmType ResolveType(IEdmType expectedType, string typeName)
{
IEdmType resolvedType = MyModel.FindType(typeName);
if (resolvedType == null)
{
var qualifiedTypeName = typeName.Contains(".") ? typeName : $"Edm.{typeName}";
caseInsensitiveCoreTypeCache.TryGetValue(qualifiedTypeName, out resolvedType);
}
return resolvedType;
}
private static Dictionary<string, IEdmType> BuildCaseInsensitiveCoreTypesCache()
{
var cache = new Dictionary<string, IEdmType>(StringComparer.OrdinalIgnoreCase);
foreach (var type in EdmCoreModel.Instance.SchemaElements)
{
cache.Add(type.FullName(), type as IEdmType);
}
return cache;
}
And here's how you would pass it to the reader settings:
messageReaderSettings.ClientCustomTypeResolver = ResolveType
from odata.net.
Let's see if we can parameterize the comparer and run benchmarks at a later time. We will need to benchmark if we can't parameterize the comparer for some reason.
from odata.net.
Related Issues (20)
- Allow using unmapped properties getters in queries HOT 3
- Referential constraint 'Fred' HOT 2
- ODataException is thrown when getting a worksheet range via Microsoft.Graph API HOT 7
- Nav prop on complex type returned from a collection
- Mitigate ArgumentOutOfRangeException when the typename in context URL is not fully qualified HOT 2
- Querying by primary key throws exception if element doesn't exist HOT 1
- EdmLib successfully parses type names with unbalanced parens HOT 1
- Issue with data conversion errors. HOT 5
- Remove `IContainerProvider` and pass the `IServiceProvider` directly to the message reader or writer HOT 4
- Remove `ODataMessageInfo` from the DI container
- ODL 8 breaking changes tracking
- re: CustomUriFunctions should not be static or irreversible
- Filter on nullable DateOnly seems not supported HOT 2
- Set license expression on nuget packages
- ODataException is thrown when getting a worksheet table rows via Microsoft.Graph API HOT 2
- Exception thrown when trying to create EdmTargetPath from string path that contains type casts HOT 1
- WritesJsonElementCorrectly() test fails Intermittently in the release pipeline HOT 2
- Scale facet value has wrong scaling
- Unhandled Exception: System.TypeInitializationException: The type initializer for 'Microsoft.OData.Edm.Vocabularies.V1.CoreVocabularyModel' threw an exception. ---> System.BadImageFormatException: Could not load file or assembly 'System.Reflection, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. Reference assemblies should not be loaded for execution. They can only be loaded in the Reflection-only loader context. (Exception from HRESULT: 0x80131058) ---> System.BadImageFormatException: Cannot load a reference assembly for execution.
- NullReference exception generated when using FilterClause.ApplyTo method with open properties in the filter query
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from odata.net.