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

  • SEARCH
  • Home
  • 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 1026263
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T12:03:20+00:00 2026-05-16T12:03:20+00:00

extremely sorry for writing here, I’m a php guy, been doing .NET MVC for

  • 0

extremely sorry for writing here, I’m a php guy, been doing .NET MVC for like three days, although I had experience with C# some time ago. Anyways, I’m doing a simple website with shops and news stories. A news story could be either a global one, or tied to some shop. I use ShopId in the News table which can be 0.

What I’m trying to achieve is get the news which are not tied to any shop, and then in a different section get those tied to shops (where ShopId > 0) and I’d like to list them in a nice format, like: Shop Name — News heading, where the shop name would lead to the shop’s page, and the news heading would lead to the news page.

The problem is that both Shops and News have fields called Name and Slug. I’m using the following code to retrieve the news alone:

var news = db.News.Include("User").Where(s => s.ShopId == 0)
  .OrderByDescending(d => d.PublishDate).ToList();

Which seems to work fine. My method for retrieving news together with shops is currently the following:

var shopsNews = db.News.Include("User").Include("Shop").Where(s => s.ShopId > 0)
  .OrderByDescending(d => d.PublishDate).ToList();

In order to understand the structure of my database I posted it to Twitpic: http://twitpic.com/2im4xm

Any help would be appreciated. Thanks!
~ K

  • 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-16T12:03:21+00:00Added an answer on May 16, 2026 at 12:03 pm
    var q = from n in db.News
            orderby n.PublishDate desc
            select new NewsPresentation // view model class you write
            {
                ShopName = n.ShopId == 0 ? "No shop, sorry!" : n.Shop.Name,
                NewsName = n.Name,
                UserName = n.User.Name,
                // etc.
            };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This feels like an extremely n00b question, but here goes... I have a series
Sorry about the extremely vague question title (any suggestions for improvements welcome) I have
I am doing some extremely large array processing. I do a global declaration of:
Still extremely new to the whole MVC/LINQ thing. I'm in the processes off building
Note: I'm sorry if this is an extremely simple question but I'm somewhat obsessive
I have a question about regex/Python. Sorry if this topic has been discussed millions
This sounds like a relatively simple question, but I haven't been able to get
Sorry if this is extremely obvious, but I have looked and looked for a
I'm new to Rails so sorry for the extremely basic question. I'm trying to
I've been playing around with WPF for a while and I like how it

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.