Problem creating a LINQ query, filtering old duplicates, VB
-
Monday, March 03, 2008 7:23 PMHello,
I've got a problem and It seems I'm not able to solve it...
I have a table with circa these fields (simplified)
autoID, TruckPlate, Departure Location, Arrival Location, departure date, arrival date
this table is filled of recurring TruckPlates that go from a location to another, and again and again. so I have many similar truckplates in the table, because the truck number of the company is limited of course
What I need is a situation of what trucks are at the moment of the query in a given "arrival location",
so i need first to distinct all the plates ordered by arrival date descending, to remove duplicate.
so I have a list of most recent unique plate in the table
and then keep just the ones have arrival in (for example) London.
and select all fields of these records in my datagridview table
I created a combined query, with a first query that distincts the truck plates by date and the second one that make a for each of the 1° query and select the ones with the given location
but I'm not able to put it in the table all together!
is like this, (more or less..)
dim queryuniqueplate = from truck in db.travels ....order by date descselect truck.plate distinct
for each plate in queryuniqueplate
when i press next i can see all the results but i want to see them all together in the table! not load them one at a time, how can i do it?dim queryLondon = from t in db.travelswhere arrival like "london"select t
me.truckingbindingsource.datasource = queryLondon
msgbox("next") ->>>>> (to remove, just something that shows the query works)
next
I hope I was clear, is not very easy to explain
All Replies
-
Thursday, March 06, 2008 6:10 AM
Hi Valnuke,
Perhaps you can try the following code snippet to combine the two queries above.
Code Snippetdim queryuniqueplate = from truck in db.travels
order by date desc
select truck.plate distinct, truck.autoID, truck.arrival, truck.deparure, truck.date
For Each c In queryuniqueplate
Debug.WriteLine(c)
Next
For more information about LINQ in VB.Net, please check the URL below.
http://msdn2.microsoft.com/en-us/library/bb763068.aspx
Regards,
Xun

