OData Expand Fails with Client Win8.1 Generic Application

Just a quick question, is this not supported in the universal Win 8.1 class library? Or, if so, can someone help with what I'm doing wrong.

http://jbsapplication.azurewebsites.net/Modules?$filter=Name%20eq%20'JBS%20Electronic%20forms'&$expand=Menus 

When I do this from a browser or Fiddler, I get the correct answer.

My code in the client view model class is as follows (using the created OData Client v2 objects)

 var application = new UriBuilder(ServiceBaseAddress); var context = new Models.Application(application.Uri); var modulesQuery = context.Modules.Expand(m=>m.Menus).Where(m => m.Name == ApplicationName); var modules = await ((DataServiceQuery<Module>) modulesQuery).ExecuteAsync(); _currentModule = modules.FirstOrDefault(); 

In the last line

the following exception is thrown:

The first exception of type exception "Microsoft.OData.Core.ODataException" occurred in Microsoft.OData.Core.DLL

Additional information: When writing a JSON response, the user model must be specified, and the set of objects and entity type must be passed to the ODataMessageWriter.CreateODataEntryWriter method, or ODataFeedAndEntrySerializationInfo must be set to the ODataEntry or ODataFeed that is written.

If I delete the Expand Query part, everything will be fine, but I need to do another round trip to get the menu.

Broken link for module class:

 [Key("Id")] public class Module: BindableBase { public string Name { get { return _name; } set { SetProperty(ref _name, value); } } DataServiceCollection<Menu> _menus = new DataServiceCollection<Menu>(null,TrackingMode.AutoChangeTracking); public DataServiceCollection<Menu> Menus { get { return _menus; } set { _menus = value; OnPropertyChanged("Menus"); } } } 
+5
source share
2 answers

I ran into a problem that you described when I forgot to add an expandable object to ODataModelBuilder as an EntitySet. Try this in your ASP.NET OData API:

 builder.EntitySet<Menus>("Menus"); 
+5
source

Models with an identification property must be explicitly extended by clients, and extensible models must be registered as entities with a creator for an OData auto-generated client in order to be able to name an extension.

0
source

Source: https://habr.com/ru/post/1204605/


All Articles