D
David
Hi all,
Still trying to understand Linq at the moment. Parts of the project, I am
still using Sql queries because of my limited knowledge of linq.
A problem I have is doing left joins. I have tried following some examples
on the net but then for some reason, I don't understand how I can get data
out.
I have two tables...
ServiceSheets and TrailerDetails.
In ServiceSheets, I have a SheetID and TrailerID
In TrailerDetails, I have TrailerID and ServiceDueDate
The ServiceSheets is the primary table, I need to left join TrailerDetails.
In Sql, I would do something like...
select * from ServiceSheets left join TrailerDetails on
ServiceSheets.TrailerID = TrailerDetails.TrailerID where
ServiceSheets.SheetID = '123'
The mapping should actually be a 1 to 1 (i.e. only one trailer in
trailerdetails that matches the servicesheet trailer) or 1 to 0 (no trailer
exists yet that matches the servicesheet trailer)
There will only ever be one result from the above SQL, which is based on a
unique SheetID, but there could be more than one sheet in ServiceSheets with
the trailer ID.
My current code looks like... (C#)
using (TrailerDataClassesDataContext dc = new
TrailerDataClassesDataContext())
{
var sheet = from Sheet in dc.ServiceSheets
//join Trailer in dc.TrailerDetails on
Sheet.TrailerID equals Trailer.TrailerID
where Sheet.SheetID == Request.QueryString["sheet"]
select Sheet;
TrailerIDTextBox.Text = sheet.First().TrailerID;
}
As you can see, I have remarked the join out because if I select a sheet
with no trailerdetail, the app stops. (As I understand the join, it is a
right join.) The other samples I found, I couldn't then extract the data
out of the query like I am doing in the sample above.
I need to learn from this, so any help that is given, I would appreciate the
knowledge to understand what is happening in the Linq query.
Thank you for your time.
--
Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available
Still trying to understand Linq at the moment. Parts of the project, I am
still using Sql queries because of my limited knowledge of linq.
A problem I have is doing left joins. I have tried following some examples
on the net but then for some reason, I don't understand how I can get data
out.
I have two tables...
ServiceSheets and TrailerDetails.
In ServiceSheets, I have a SheetID and TrailerID
In TrailerDetails, I have TrailerID and ServiceDueDate
The ServiceSheets is the primary table, I need to left join TrailerDetails.
In Sql, I would do something like...
select * from ServiceSheets left join TrailerDetails on
ServiceSheets.TrailerID = TrailerDetails.TrailerID where
ServiceSheets.SheetID = '123'
The mapping should actually be a 1 to 1 (i.e. only one trailer in
trailerdetails that matches the servicesheet trailer) or 1 to 0 (no trailer
exists yet that matches the servicesheet trailer)
There will only ever be one result from the above SQL, which is based on a
unique SheetID, but there could be more than one sheet in ServiceSheets with
the trailer ID.
My current code looks like... (C#)
using (TrailerDataClassesDataContext dc = new
TrailerDataClassesDataContext())
{
var sheet = from Sheet in dc.ServiceSheets
//join Trailer in dc.TrailerDetails on
Sheet.TrailerID equals Trailer.TrailerID
where Sheet.SheetID == Request.QueryString["sheet"]
select Sheet;
TrailerIDTextBox.Text = sheet.First().TrailerID;
}
As you can see, I have remarked the join out because if I select a sheet
with no trailerdetail, the app stops. (As I understand the join, it is a
right join.) The other samples I found, I couldn't then extract the data
out of the query like I am doing in the sample above.
I need to learn from this, so any help that is given, I would appreciate the
knowledge to understand what is happening in the Linq query.
Thank you for your time.
--
Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available