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

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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:38:23+00:00 2026-06-14T06:38:23+00:00

I have a Model, which is below: [Table(WebsiteText)] public class WebsiteTextModel { [Key] [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]

  • 0

I have a Model, which is below:

[Table("WebsiteText")]
public class WebsiteTextModel
{
    [Key]
    [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
    public int ID { get; set; }

    public string WebsiteSection { get; set; }

    [DataType(DataType.MultilineText)]
    public string TextToDisplay { get; set; }
}

I have a DataContext class, which is below:

public class WebsiteTextContext : DbContext
{
    public WebsiteTextContext()
        : base("DefaultConnection")
    {

    }

    public DbSet<WebsiteTextModel> WebsiteText { get; set; }
}

I want to use LINQ to get the website text for my homepage, and stuff it into the ViewBag, so I am trying this:

public ActionResult Index()
{
    var context = new WebsiteTextContext();

    var result = from x in context.WebsiteText
                 where x.WebsiteSection == "Home Page"
                 select x.TextToDisplay;

    ViewBag.Message = result;

    return View();
}

However var is IQueryable, and I can’t figure out how to get it to string. This doesn’t work:

string result = from x in context.WebsiteText
    where x.WebsiteSection == "Home Page"
    select x.TextToDisplay;

This doesn’t work:

var result = from x in context.WebsiteText
    where x.WebsiteSection == "Home Page"
    select x.TextToDisplay.ToString; //It's still IQueryable<String>

And this doesn’t work:

var result = from x in context.WebsiteText
    where x.WebsiteSection == "Home Page"
    select x.TextToDisplay.ToArray; //It's now IQueryable<char[]>

What do I need to do?

  • 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-14T06:38:24+00:00Added an answer on June 14, 2026 at 6:38 am
    string result = (from x in context.WebsiteText
    where x.WebsiteSection == "Home Page"
    select x.TextToDisplay).FirstOrDefault();
    

    You also have First and Single and SingleOrDefault

    Look them all up and pick which version works best for you.

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

Sidebar

Related Questions

I have a Model which has some constants defined, like below: class Order(models.Model): WAITING
In the example below, I have a model Proof which contains a foreign key
I have a model which has a certain behaviour implemented. class X { ....
I have a class which inherit from DropCreateDatabaseIfModelChanges. public class SetupData : DropCreateDatabaseIfModelChanges<CyclingClubContext> {
I have below defined in my model: public $belongsTo = array( 'User' => array(
I have a users_manager engine which has a User model class. In an other
I have a stored procedure (see below) which inserts data into a physical table
I have model Foo which has field bar. The bar field should be unique,
I have a model which contains lists of other models, which also contains lists
I have django model which consist of parent child relationship filed I want to

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.