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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T19:56:07+00:00 2026-05-31T19:56:07+00:00

I have an events table with a ‘featureEvent’ boolean column. I need to display

  • 0

I have an events table with a ‘featureEvent’ boolean column.

I need to display a featured event of the day on the home page

what id like to do is display the featured event for the entire day. For this i think i need to link it to the date somehow.

public Event GetTodaysFeatureEvent()
{
    var ev = db.Events.Where(x => x.featureEvent == true && x.eventDate> DateTime.Now.Date);
    //gets a pool of feature-able events
}

how can I do it so that whatever event is displayed is the same one for the entire day?

Edit – I’ll try making more sense.

I set events to be featureable (featureEvent=true). what i want to do is pick out from a pool of featurable events (that will occur in the future) one single event.

i dont want to use firstOrDefault as this could potentially show the same event N days in a row. ideally I’d like something whereby a different event is selected from the featurable events each day… i cant just pick a random one as during the same day different events will be featured and for different users. so i want that one event to be shown the entire day to all users.

I dont mind featuring the same event more than once, ie if all the featurable events have already been featured then go back to the first one?

now it gets even more complicated as i can set an event to featured at any time so not sure how to handle that side of things.

hope thats a little clearer….probably not!

  • 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-05-31T19:56:09+00:00Added an answer on May 31, 2026 at 7:56 pm

    (This answer assumes that eventDate always has a time component of zero — in other words, that the value would always be something like 12/31/2012 00:00:00.000 and never something like 12/31/2012 11:30:00.000.)

    Note that your logic only chooses events occurring after today. To choose events occurring today or later, change > to >=. To choose events occurring today only, use ==.

    If it is possible to have more than one feature event for a given day, you can do this in one of two ways

    1. pick an arbitrary item, and save a reference to it somewhere so you can reuse it, or

    2. apply some unambiguous ordering to your linq query, so that the objects are guaranteed always to have the same order; then pick the first one.

    For example, assuming there’s a property P whose value is unique to each event, and whose type is T where T implements IComparable<T>, then you could do this:

    public Event GetTodaysFeatureEvent() 
    { 
        var ev = db.Events.Where(x => x.featureEvent && x.EventDate >= DateTime.Now.Date)
            .OrderByDescending(x => x.EventDate)
            .ThenBy(x => x.P)
            .FirstOrDefault();
    } 
    

    This picks a future event that occurs on the next day for which there’s at least one event. Since the events are ordered by P, and P is by assumption unique, the events will always be retrieved in the same order.

    If you prefer to display featured events only on the actual day (and display nothing on days that have no featured events), then change the >= to ==:

    public Event GetTodaysFeatureEvent() 
    { 
        var ev = db.Events.Where(x => x.featureEvent && x.EventDate == DateTime.Now.Date)
            .OrderByDescending(x => x.EventDate)
            .ThenBy(x => x.P)
            .FirstOrDefault();
    } 
    

    In response to your edits:

    ideally I’d like something whereby a different event is selected from the featurable events each day… i cant just pick a random one as during the same day different events will be featured and for different users. so i want that one event to be shown the entire day to all users.

    To achieve this, you’ll definitely need persistent information about which event is featured on a given day. It seems now that your question is more about how to do that than about specific linq expressions.

    I dont mind featuring the same event more than once, ie if all the featurable events have already been featured then go back to the first one?

    If you want to make sure that events aren’t featured repeatedly before all other events have been featured, you could save a “lastFeaturedOn” date for each featured event. When choosing an event to feature, first pick one that was never featured (i.e., lastFeaturedOn == null); if there are no such events, pick the one with the smallest lastFeaturedOn date.

    This will give you the events in the same repeated order; if you’d rather reshuffle them you could instead set all dates to null when they are all non-null (or use a boolean).

    Once you’ve picked an event, you’ll need to save it and a date in your database, to identify it as the featured event for that date. You could use the “lastFeaturedOn” date, and define “today’s featured item” as “the item whose lastFeaturedOn date is today’s date.”

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

Sidebar

Related Questions

I have a table of events, I need to find all tail events of
I have a table called Event. A column has duration--which is...how long that event
I have tables named Events and Log. The Events table comprises of ID, Event
I have a table with an event id pk, date column and an event
I have an events table and need to pull the 4 closest dates to
I have 2 tables events and events_visibility events table and the column id -
I have Event HABTM Category with categories_events table. I want to display only Event
I have an Events table whose goal is to store actions done by web
I have a table of events with a recorded start and end time as
I have a table of data which represents a series of events that persons

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.