Problem: Looking to select 1 row of each type
Table: EntryPrices
AttendingTypesId (int)
Name (nvarchar)
Price (int)
GroupId (int)
FromDate (DateTime) //yyyy-MM-dd
Sample:
Basic entry – 100 – 1 – 2012-08-01
Sponsor entry – 350 – 2 – 2012-08-01
Staff entry – 70 – 3 – 2012-08-01
Basic entry – 150 – 1 – 2012-10-01
Basic entry – 200 – 1 – 2012-12-01
As you can see, there are 3 basic entries. Each is valid depending on the date when they registered.
So if a person registers in mid september, he gets it for 100
mid November 150 and end December 200.
However i want to get the “valid” fee depending on todays date and i want to list that in a dropdown list.
So if i query this today (2012-aug-02) i should get the following
rows:Basic entry – 100 – 1 – 2012-08-01
Sponsor entry – 350 – 2 – 2012-08-01
Staff entry – 70 – 3 – 2012-08-01
If i query this (2012-dec-20) i should get the following rows:
Sponsor entry – 350 – 2 – 2012-08-01
Staff entry – 70 – 3 – 2012-08-01
Basic entry – 200 – 1 – 2012-12-01
How can i construct this in linq-to-sql?
My idea was something like:
var f = from data in mc.AttendingTypes
where DateTime.Now.CompareTo(data.FromDate) > 0
group data by new { data.GroupId, data.Name, data.Price, data.AttendingTypesId }
into newData
select new { newData.Key.Name, newData.Key.Price, newData.Key.AttendingTypesId };
I’d rather do something like that :