Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6047497
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:21:27+00:00 2026-05-23T07:21:27+00:00

I have a model where a place has some descriptions, those descriptions are associated

  • 0

I have a model where a place has some descriptions, those descriptions are associated with interests (place.description.interests). A user looking at the view for a place is represented in the model as a user, who also has a number of interests.

What I want to do is sort the description by overlapping interests (including zero overlapping), where my current Linq is:

place dest = (from p in _db.places
                          where p.short_name == id
                          select p).Single();

 return View(dest);

Now the following will do what I want in SQL on the schema in question:

SELECT COUNT(interest_user.user_id) AS matches, description.*
FROM description JOIN interest_description ON description.user_id = interest_description.user_id AND description.place_id = interest_description.place_id
    JOIN interest ON interest_description.interest_id = interest.interest_id
    LEFT JOIN interest_user ON interest.interest_id = interest_user.interest_id 
WHERE interest_user.user_id = 2
    AND description.place_id = 1
GROUP BY interest_description.user_id, interest_description.place_id
ORDER BY matches DESC

But I’m too new to Linq to know how I would handle this correctly. Ideally I could pull this off while still passing in a strongly typed model.

I have managed this so far:

var desc = from d in _db.descriptions
                       from i in d.interests
                       from u in i.users.DefaultIfEmpty()
                       where d.place_id == PlaceID
                           && (u.user_id == userID

(PlaceID and UserID are arguments passed to the controller that is managing this).

Simply put, given this linq, I just need to return d, ordered by a count of i.

my model
enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T07:21:27+00:00Added an answer on May 23, 2026 at 7:21 am

    when your linq query becomes overly complex, i will suggest you creating views in your database and putting them on dbml designer. I have experienced at couple of situations when doing a lot of grouping in linq queries resulted in inefficient sql. Using views will not only result in straight forward linq queries but it also uses the sql that you want.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have model Article it has field title with some text that may contain
I have a User model that, in my mind, has two show actions: A
I have model Foo which has field bar. The bar field should be unique,
I am newbie at Django. I have model with a custom method. In view
I have a ViewController class that has a property that is the model which
I have a JTable using a custom DefaultTableModel which has some Booleans in the
I have a 3D model which has position, uv, normal, indices info. I need
I have a user model in which I have a method for seeing if
I have a bit of a problem! I have a Place model and a
Introduction The Model-View-Controller approach has been in my head since before the holidays and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.