I am having a meltdown over something that seems so simple and yet isn't working. Here's my scenario.
I have an object structure of tEvents, which contains properties of an event like a run of concerts. tEvents in turn contains an entity set of tEventOptions, which include properties like EventDate, Cancelled etc. I would like to query a list of tEvents using properties of the tEventOptions, for example filtering by date.
My pageis using a calendar object to show event dates. So I am trying to find if any tEvents in the List coming back from the database match the date of the day element being rendered in my Calendar control like so (in this snip 'data' is List and results from a db query):
protected void CalendarDayRender(object sender, DayRenderEventArgs e){
//need to see if we can find a way to find an event option that might be contained within the events datasource
var r =( from x in data where x.tEventOptions.Select(y=>y.EventDate.Date.Equals(e.Day.Date)).Any() select x).Any();
if (r)
{
e.Cell.Font.Bold = true;
}
}
So r should be true if there are any tEvents that have tEventOption with any EventDate that matches the DayRenderEventArgs Dat开发者_Go百科e. 'EventDate' is a datetime field, so I am taking only the date part of it to compare with 'e.Day.Date'. My thought was that taking 'Any()' of the query on tEventOptions gives me a boolean as to whether any elements match the condition.
Except r, my query result var, is always true no matter what data it receives. I have tried the sub query using other properties of tEventOption and get the same 'true' result each time. I know that the data does not reflect this result so I clearly have a problem with the structure of my query, but for the life of me I cannot find a way to resolve it.
I have struggled with this type of query before, so any help would be very gratefully received.
try this
e.Cell.Font.Bold = data
.Where(x => x.tEventOptions
.Any(o => o.EventDate.Date == e.Day.Date));
精彩评论