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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T23:08:56+00:00 2026-06-10T23:08:56+00:00

I am trying to convert the below mentioned SQL query to LINQ query Qry

  • 0

I am trying to convert the below mentioned SQL query to LINQ query

Qry = "select Announcement, StartDate, Enddate,Annkey from
Announcements ";   Qry = Qry & " where Startdate <= #" & Today & "# " 
Qry = Qry & " and Enddate >= #" & Today & "# "  Qry = Qry + " order by
StartDate, Enddate";

What I have made so far –

public bool Selectdatafromannouncements()
        {


            List<Announcement> lstAnnounce = new List<Announcement>(
                from l in objVaccinationContext.Announcements
                where
                    l.StartDate.Value < DateTime.Today
                    && l.EndDate.Value < DateTime.Today
                orderby l.StartDate, l.EndDate
                select new (l.Announcement1, l.StartDate, l.EndDate, l.AnnouncementID)
                );


            return true;
        }

Getting an error near select new ( as type expected please help me out i am a beginner with LINQ

  • 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-10T23:08:58+00:00Added an answer on June 10, 2026 at 11:08 pm

    You don’t need a constructor here, for creating the list.
    The curly braces are used for creating anonymous objects, so instead of declaring lstAnnounce of List<Announcement> type, better use the var keyword.

    So you can have this:

    var query = from l in objVaccinationContext.Announcements
                      where
                        l.StartDate.Value < DateTime.Today
                        && l.EndDate.Value < DateTime.Today
                    orderby l.StartDate, l.EndDate
                    select new {l.Announcement1, l.StartDate, l.EndDate, l.AnnouncementID };
    var lstAnnounce = query.ToList();
    

    If you need a list of Annoucement objects:

    var query = 
                    from l in objVaccinationContext.Announcements
                    where
                        l.StartDate.Value < DateTime.Today
                        && l.EndDate.Value < DateTime.Today
                    orderby l.StartDate, l.EndDate
                    select l;
    List<Announcement> lstAnnounce = query.ToList();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to convert the below SQL query to HQL and am having a
I have spent a great deal of time trying to convert the query below
I am trying to convert the code below to a shorthand linq, but not
I am trying to convert the code below from VB6 to C#. I am
I'm have been trying to convert the foreach statement below to a LINQ statement
I am trying to convert the code below to a lambda expression from b
How to do an update in LINQ to Objects. Trying convert SQL to Linq
I'm trying to convert a SQL Server 2008 R2 Express query in ASP-Classic that
I'm trying to convert the below bit of code into VB (and obviously apply
Any help would be appreciated, I'm trying to convert the code below to C#,

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.