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 6128959
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:41:12+00:00 2026-05-23T16:41:12+00:00

This is my model; namespace AtAClick.Models { public class LocalBusiness { public int ID

  • 0

This is my model;

namespace AtAClick.Models
{
    public class LocalBusiness
    {
        public int ID { get; set; }

        public string Name { get; set; }
        public int CategoryID { get; set; }
        public string address { get; set; }
        public string desc { get; set; }
        public int phone { get; set; }
        public int mobile { get; set; }
        public string URL { get; set; }
        public string email { get; set; }
        public string facebook { get; set; }
        public string twitter { get; set; }

        public string ImageUrl { get; set; }

        public virtual Category Category { get; set; }

    }

    public class Category
    {
        public int CategoryID { get; set; }
        public string Name { get; set; }

        public virtual ICollection<LocalBusiness> Businesses { get; set; }
    }

}

I have a view which lists the categories and one which lists the businesses. I want another which list all the business in a certain category My question is, what would my Linq query in my controller look like? Something like..

var companyquery = from c in db.LocalBusiness
                   where c.Category = Category.Name
                   select c;

But obvioulsy this isn’t working. I’m new to all this so thanks in advance for the help, and if you need anymore detail just ask. Thanks!!

My controller, is this what you mean?

 public ViewResult Browse(int id)
 {

            int categoryID = id;

            var companyquery = from c in db.LocalBusinesses
                               where c.Category.CategoryID == categoryID
                               select c;

            return View(companyquery);
 }
  • 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-23T16:41:13+00:00Added an answer on May 23, 2026 at 4:41 pm

    You’re comparing a category object (c.Category) with a static field of the Category class (Category.Name). The static field does not exist and therefor this will not compile.

    You should have a variable stating the specific category object, or at least an identifier (like the CategoryID). Name is not enough, since this property is not unique (it’s possible to have two different categories with the same name).

    So, let’s say you obtain a specific CategoryID somehow, then your LINQ query would look like:

        // The category ID to filter.
        int categoryID = 42;
    
        // Retrieve all companies that are listed under the given category.
        var companyquery = from c in db.LocalBusiness
                           where c.Category.CategoryID = categoryID
                           select c;
    

    Your categoryID could, for instance, be obtained from a query parameter (declare as a controller method parameter).

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

Sidebar

Related Questions

I have a code first model: namespace InternetComicsDatabase.Models { public class Issue { [Key]
I have a simple model namespace StackOverflow.Models { public class Test { public Test()
I defined a model like this public class Planilla { [Key] public int IDPlanilla
i have this model and configuration public class Person { public int? FatherId {
I have a class in my domain model root that looks like this: namespace
I have this model in django: class JournalsGeneral(models.Model): jid = models.AutoField(primary_key=True) code = models.CharField(Code,
Let's consider this model class Session(models.Model): tutor = models.ForeignKey(User) start_time = models.DateTimeField() end_time =
In one namespace (Ventosa.Graphics) I have a public class named Model namespace Ventosa.Graphics {
Consider this simple Model and ViewModel scenario: public class SomeModel { public virtual Company
I'm using Doctrine ODM with MongoDB. I have a product model like this: namespace

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.