c# 4.0 - Why don't ODataQueryOptions work for both sides of a 1..* relationship? -


i have 2 tables joined link table , exposed through odata / entity framework:

  • users
  • usergroup

using ~/api/users, following [user] api controller action returns results:

    public ienumerable<user> get(odataqueryoptions<user> options)     {         var unitofwork = new atms.repository.unitofwork(_dbcontext);          var users = options.applyto(unitofwork.repository<user>().queryable                                               .include(u => u.usergroups)                                               .orderby(order => order.username))                                               .cast<user>().tolist();          unitofwork.save();      // includes dispose()          return users;     } 

i am, however, unable apply odataqueryoptions following [usergroup] api controller action:

    public ienumerable<usergroup> get(odataqueryoptions<user> options)     {         var unitofwork = new atms.repository.unitofwork(_dbcontext);          var usergroups = options.applyto(unitofwork.repository<usergroup>().queryable                                 .include(u => u.users)                                 .orderby(order => order.groupname))                                 .cast<usergroup>().tolist();          unitofwork.save();      // includes dispose()          return usergroups.asqueryable();     } 

when do, following error:

cannot apply odataqueryoptions of 'dal.user' iqueryable of 'dal.usergroup'.

instead, have omit options.applyto(...):

        var usergroups = unitofwork.repository<usergroup>()                                 .query()                                 .include(u => u.users)                                 .get()                                 .orderby(order => order.groupname); 

can please explain me why is?

thanks.

the error message says all. cannot apply query meant applied on collection of users on collection of user groups. change parameter type odataqueryoptions<usergroup>.


Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -