Last active
August 8, 2022 13:03
-
-
Save MatthewDavidCampbell/7f0433966742fb4ffd05a6f24a3df18b to your computer and use it in GitHub Desktop.
Extends OData client context (DataServiceContext)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.OData.Client; | |
using Microsoft.OData.Edm; | |
using System; | |
namespace Biometria.Discovery.OData | |
{ | |
public class AzureSearchContext : DataServiceContext | |
{ | |
public AzureSearchContext(string url) : base(new Uri(url)) | |
{ | |
Actors = base.CreateQuery<Actor>("aktor/docs"); | |
Format.LoadServiceModel = () => | |
{ | |
EdmEntityType actor = new EdmEntityType(typeof(Actor).Namespace, nameof(Actor)); | |
EdmStructuralProperty identity = actor.AddStructuralProperty(nameof(Actor.Identitet), EdmPrimitiveTypeKind.String); | |
actor.AddKeys(identity); | |
EdmModel model = new EdmModel(); | |
model.AddElement(actor); | |
return model; | |
}; | |
Format.UseJson(); | |
Configurations.RequestPipeline.OnMessageCreating = (args) => new AzureHttpClientRequestMessage(args); | |
} | |
public DataServiceQuery<Actor> Actors { get; } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Edm model has to be built explicitly otherwise the search query properties are not correctly defined. Mapping from Azure Search index definition in JSON to EDM XML probably the best solution.