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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T20:32:09+00:00 2026-06-10T20:32:09+00:00

Using MVC3 VS2010 and SQL Server 2008 Express I am trying to filter based

  • 0

Using MVC3 VS2010 and SQL Server 2008 Express
I am trying to filter based on two SQL Server tables and display the result.
One table is clients table and the other is agent. They have in common ClientAgentID in the clients table and ID in the Agents table. An agent logs and should be able to see the clients assigned to the agent. If you have any ideas on the best way to do this please help me. So far I am trying to filter in the clients controller and here is what I have but the message is I am getting is in the title.

 public ActionResult Index()
    {
        //This displays all the clients not filtered by the Agent ID number
        //var clientItems = db.MVCInternetApplicationPkg;
        //return View(clientItems.ToList());

        //Trying to filter by the agent name given in the login page then finding 
        //the agent ID

        var getAgentID = from a in db.AgentsPkg
                            where a.AgentLogin == User.Identity.Name
                            select a.ID;

        var clientItems = from r in db.MVCInternetApplicationPkg
                          where Convert.ToString(r.ClientAgentID)
                                == Convert.ToString(getAgentID)
                          select r;
        //THIS IS THE LINE OF CODE THAT SHOWS THE ERROR MESSAGE
        return View(clientItems.ToList());
    }

This is my first MVC project after the Music Store so am willing to learn and accept any help or advice.
Cheers

Here is the solution that I used in the end. Any feed back on if this is a good approach would be appreciated

 public ActionResult Index()
    {

        var innerJoint = from agents in db.AgentsPkg where agents.AgentLogin == User.Identity.Name
                         join clients in db.MVCInternetApplicationPkg on agents.ID equals clients.ClientAgentID
                         select clients;

        return View(innerJoint.ToList());
    }
  • 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-06-10T20:32:10+00:00Added an answer on June 10, 2026 at 8:32 pm

    1. Reason for the error:

    As others have stated, it’s due to the use of Convert.ToString() within your where clause, which Linq cannot convert into SQL. I would expect your original query to work just by removing the two Convert.ToString() functions.

    2. “….best way to do this”:

    Well, a better way…. 🙂

    In Entity Framework, the easy way to navigate between related entities is via Navigation Properties. If your approach is “Database First”, these should be generated for you in your EDMX. If your approach is “Code First”, there’s a good post here describing how to set this up.

    Either way, I’d expect your Client class to have a navigation property to Agent (i.e. similar to OrderDetail’s Order property in the MvcMusicStore sample you mention):

    public virtual Agents Agent { get; set; }
    

    Then your method becomes very simple (i.e. similar to many of the controller methods in MvcMusicStore) …no Joins or multiple statements required:

    var clients = db.MVCInternetApplicationPkg.Where(c => c.Agent.AgentLogin == User.Identity.Name); 
    return View(clients.ToList()); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using MVC3 VS2010 with EF4.1, I have created my DB using SQL Server
I'm using MVC3 with C# code. I have a table in my SQL Server
I am using Visual Studio 2010 with MVC 3 and MS SQL SERVER 2008
I am using VS 2010, MVC 3.0, SQL Server Standard edition (not Express). I
I am using MVC3 with Razor, for display a grid I am using a
I'm using MVC3 with a detailed view that needs to display a formatted dollar
I am using MVC3, EF Model first. I have a form with two DropDownList
I'm using MVC3 razor, and I'm trying to pass an object to a partial
Using MVC3 for the first time, so sorry for the noob-like question. I'm trying
we are developing a web application using MVC3 and VS2010. We have some pdf

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.