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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:30:53+00:00 2026-06-15T23:30:53+00:00

Below is a Linq query I’m using in one of my ASP MVC controllers.

  • 0

Below is a Linq query I’m using in one of my ASP MVC controllers. I am attempting to pull one record from an SQL database, and then compare it with the user’s input. If the state code the user entered does not match the state code associated with the product code the user has entered, it will kick back an error message.

I’m stuck, though, on how to access the StateCode field from the “course” variable. Using Visual Studio I can step through the code and see the value in there (while examining via the Locals window/readout), however I do not know how to get the value I’m looking for.

This is my first time using Linq, so any and all help/suggestions will be greatly appreciated. Thanks!

                var course = from c in db.AgentContEd
                             where c.CourseCode == agentconted.CourseCode
                             select c;

                if (agentconted.StateCode.Equals(course.StateCode))
                {
                    db.AgentContEd.Add(agentconted);
                    db.SaveChanges();
                    return RedirectToAction("Details", "Agent", new { id = agentconted.SymetraNumber });
                }
                else
                {
                    ViewBag.ErrorMessaeg = "State code must match Product Training state code";
                }
  • 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-15T23:30:53+00:00Added an answer on June 15, 2026 at 11:30 pm

    You are pulling back an IQueryable<T> when you instead need a single entity. If your query produces no resulting record, course will be set to null. A query that returns more than 1 record will throw an exception.

    (from c in db.AgentContEd
    where c.CourseCode == agentconted.CourseCode
    select c)
    .SingleOrDefault();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have linQ query like the one below var records = (from P in
I need to convert a sql statement to a linq query. The code below
I would like to know how to convert SQL query listed below into LINQ
I have a simple LINQ-to-Entities query as below: var BillingNumbers = from o in
Every time I write a program of the form below using LINQ to SQL,
hi guys i am stuck converting below sql to LINQ query. all i want
I'm not able to call take method from below linq query var data =
Hi i have a linq query below var Free = (from row in dt.AsEnumerable()
I'm converting the Linq query below from C# to VB.Net. Can you spot my
Let's say I have a linq query like the one below var LinqResult =

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.