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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:46:51+00:00 2026-06-12T12:46:51+00:00

New to programming, I am tring to get the value of one cell from

  • 0

New to programming, I am tring to get the value of one cell from a table using c# in asp.net MVC; here what I am trying:

 DALEntities db = new DALEntities();
  var duration = db.MyTable.Where(c => c.Day == date && c.ID == id).Select(c => c.Duration);
            Session["duration"] = duration;

to get the data to a view I use, in the controller:
var temp = Session[“duration”];
ViewBag.Duration = temp;

and in the view:

 @ViewBag.Duration

I get

System.Data.Objects.ObjectQuery`1[System.String]

I would appreciate your suggestions.

  • 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-12T12:46:52+00:00Added an answer on June 12, 2026 at 12:46 pm

    You could call a .First() at the end to eagerly execute the query and get the single result matching this criteria:

    var duration = db
        .MyTable
        .Where(c => c.Day == date && c.ID == id)
        .Select(c => c.Duration)
        .First();
    

    Be careful though because if there are no records matching your .Where() clause, the .First() extension method will throw an exception. In this case you might consider using the .FirstOrDefault() method.

    I also very strongly recommend you to learn basic LINQ before learning Entity Framework and mostly before learning ASP.NET MVC. Otherwise you will be struggling a lot with ASP.NET MVC. I also recommend to people learning separate frameworks in isolation without mixing them. Once you are familiar with them you could mix in one project.

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

Sidebar

Related Questions

I am new to programming, trying to copy files from one location to another,
i am new in programming under linux and trying to get working this code:
I am fairly new to database programming and am trying to get a basic
I'm new to android programming, but one thing that I can't seem to get
I'm new to programming in general and currently trying to get a foot into
i am enthusiast and new in programming trying this simple c language code and
I'm fairly new to C programming but trying my best to understand it. I
I'm new to programming and I'm trying to do the codingbat.com problems to start.
I'm very new to programming and I am trying to write a program that
i am new kernel programming.i have been trying to load this driver program for

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.