views:

126

answers:

2

Hi i have a linq query below

var Free = (from row in dt.AsEnumerable() where row.Field("AppointmentType") == "FreeTime" select new{ row.Field("BookedDate") row.Field("TravelTime")}).Min()

what i want to do is have a minimum on the travelTime field and im not sure on how to do it i have looked on google and also on the msdn site but i cant seem to make head or tail of it

does anyone have any ideas??

Many thanks

A: 

Hope this link helps

Greco
+4  A: 

You could use an overload for Enumerable.Min():

var Free = (
  from row in dt.AsEnumerable()
  where row.Field("AppointmentType") == "FreeTime"
  select new {
    BookedDate = row.Field("BookedDate"),
    TravelTime = row.Field("TravelTime")
  }
).Min(x => x.TravelTime);

Actually, there is no need to look at the BookedDate and you should instead use

var Free = (
  from row in dt.AsEnumerable()
  where row.Field("AppointmentType") == "FreeTime"
  select row.Field("TravelTime")
).Min();

I kept your original code with a few modifications to demonstrate the syntax for creating anonymous types.

Martin Liversage
thank you for your help on this have inserted your suggestion and it works
kevinw