LINQ - How to query a range of effective dates that only has start dates

Posted by itchi on Stack Overflow See other posts from Stack Overflow or by itchi
Published on 2010-04-16T21:46:20Z Indexed on 2010/04/16 22:03 UTC
Read the original article Hit count: 416

Filed under:
|
|
|

I'm using C# 3.5 and EntityFramework. I have a list of items in the database that contain interest rates. Unfortunately this list only contains the Effective Start Date. I need to query this list for all items within a range.

However, I can't see a way to do this without querying the database twice. (Although I'm wondering if delayed execution with EntityFramework is making only one call.) Regardless, I'm wondering if I can do this without using my context twice.

internal IQueryable<Interest> GetInterests(DateTime startDate, DateTime endDate)  {
    var FirstDate = Context.All().Where(x => x.START_DATE < startDate).Max(x => x.START_DATE);
    IQueryable<Interest> listOfItems = Context.All().Where(x => x.START_DATE >= FirstDate && x.START_DATE <= endDate);
    return listOfItems;
}

© Stack Overflow or respective owner

Related posts about LINQ

Related posts about c#3.5