Sorting a list of objects by another list of objects VB.NET LINQ -


so, here's simplified version of situation: have gyms in database:

gym: gymid, name gymamenities: gymid, amenityid amenities: amenityid 

so gym, can have 0 many "amenities". along comes user prioritizes amenities important him or her:

userprefamenities: userid, amenityid, ranking 

now when searching gym in zip code, want search results in order of user preferred amenities in order of rank...

gyms = (from g in db.gyms g.zip = thisrequest.zip order g.gymamenitys.contains(from upa in thisuser.userprefamenitys order upa.rank)).tolist 

or that...

*note running above results in:

unable create constant value of type 'userprefamenity'. primitive types or enumeration types supported in context.

i think should it:

gyms = (         g in db.gyms          g.zip = thisrequest.zip          order if((from ga in g.gymamenitys                      join upa in db.userprefamenitys on ga.amenityid                                                      equals upa.amenityid                      upa.userid = thisuser.userid                      order upa.rank descending                      select ctype(upa.rank, integer?)).firstordefault(), 0)        ).tolist 

the idea find user's highest ranked userprefamenity shares amenityid of gym's amenities. if user has no matching userprefamenity value 0 taken rank.


Comments

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -