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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T00:11:01+00:00 2026-06-01T00:11:01+00:00

How to return my LINQ query result as a particular object public CountryTable GetSelectedEventInfo(string

  • 0

How to return my LINQ query result as a particular object

public CountryTable GetSelectedEventInfo(string SelectedEventID)
{
    return (CountryTable) this.context.Event.Where(
                   e => e.EventID.Equals(Convert.ToInt32(SelectedEventID)));
}

Here is my model

public class CountryTable
{
    public int EventID { get; set; }
    public string Title { get; set; }
    public DateTime Startdate { get; set; }
    public DateTime EndDate { get; set; }
    public string EventUrl { get; set; }
}

Below is my db context

public DbSet<CountryTable> Event { get; set; }

Given below is what I am trying to do

public CountryTable GetSelectedEventInfo(string SelectedEventID)
{
    return (CountryTable) this.context.Event.Where(
                   e => e.EventID.Equals(Convert.ToInt32(SelectedEventID)));
}

I need my query result to return object of type CountryTable

  • 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-01T00:11:02+00:00Added an answer on June 1, 2026 at 12:11 am

    You could use the SingleOrDefault method:

    public CountryTable GetSelectedEventInfo(string SelectedEventID)
    {
        int id = Convert.ToInt32(SelectedEventID);
        return this.context.Event.SingleOrDefault(e => e.EventID == id);
    }
    

    Notice that this method will return null if no matching record is found in your database.

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

Sidebar

Related Questions

I have a LINQ query that returns some object like this... var query =
I've got a linq query that will return 1 result which will be an
I have LINQ Query which return result in below format -- Parent1 ----Childs ------key
I have the following linq query var result = from myTypes in context.MyTypes where
I have a linq query function like (simplified): public IList<Document> ListDocuments(int? parentID) { return
I have a LINQ query in function, like below code: public object RetrieveFday(DateTime _dt)
Ive a simple linq query to return records with a null date field, just
I want a linq query to return a calculated timespan, i have used the
I've written a LINQ query that should return an int value. but I'm not
How do you return a specific type in a Linq query? I know you

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.