Long time with assigning linq values

D

David

Hi all,

I am using Linq to SQL and having some lengthy time problems with simple
assignment of values. At first, I thought it was a problem assigning to my
editlabels (these are a server control that will allow a label to become an
edit box... but I have eliminated that)

My linq is...

var sheet = from sheetRow in dc.ServiceSheets.Where( c =>
c.SheetID == Request.QueryString["sheet"])
join trailerRow in dc.TrailerDetails
on sheetRow.TrailerID equals trailerRow.TrailerID into
joinTable
from result in joinTable.DefaultIfEmpty()
join trailerBarcode in dc.TrailerBarcodes
on sheetRow.Barcode equals trailerBarcode.Barcode into
bcTable
from result2 in bcTable.DefaultIfEmpty()
select new
{
Sheet = sheetRow,
Trailer = result,
trBarcode = result2
};


My assignments are:

BarcodesMatch = sheet.First().trBarcode == null ? false
: (sheet.First().Sheet.Barcode == sheet.First().trBarcode.Barcode ?
(sheet.First().Sheet.TrailerID == sheet.First().trBarcode.TrailerID ? true :
false) : false);


string a1 = sheet.First().Trailer.ChassisNo;
string b1 = sheet.First().Trailer.MinistryNo;
string c1 = sheet.First().Trailer.Make;
string d1 = sheet.First().Trailer.Year;
string e1 = sheet.First().Trailer.CustomerFleetNo;
string f1 =
sheet.First().Trailer.MOTExpiry.Value.ToShortDateString();
string g1 = sheet.First().Trailer.ODOReading.ToString();

string h1 =
sheet.First().Trailer.ServiceDue.Value.ToShortDateString();


the string a1 to h1 were being assigned to my edit labels, but it takes just
as long to assign to a string. Just this simple operation is taking
something like 5 seconds... the BarcodesMatch (which is a bool) is taking at
least 2 seconds.

I have set up indexes on my servicesheets, trailerdetails and
trailerbarcodes, though I am not sure if my indexes are correct. I have
extracted the query that the linq generates and run it direct in SSMSE and
it only takes 1 or 2 seconds.

Any ideas on what I might do next to improve the performance? (I have other
parts of the page also taking quite a bit of time, if I can get this fixed,
then perhaps the same fix will also apply elsewhere, though I know that this
area here is the biggest bottleneck)

--
Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available
 
D

David

Doh!!!

I just tried something new and it appears to work...

I noticed that each string assignment was using sheet.First().Trailer...

So, I recoded slightly...

TrailerDetail dt = sheet.First().Trailer;

string a1 = dt.ChassisNo;
string b1 = dt.MinistryNo;
string c1 = dt.Make;
string d1 = dt.Year;
string e1 = dt.CustomerFleetNo;
string f1 = dt.MOTExpiry.Value.ToShortDateString();
string g1 = dt.ODOReading.ToString();

string h1 = dt.ServiceDue.Value.ToShortDateString();

This has made quite a bit of difference, by assigning sheet.First().Trailer
then calling from that assingment.

Who'd have thunk it? I think I will now be reviewing all my code for this.

However, if you can think of other ways to speed me up a bit, it will be
appreciated.

--
Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available


David said:
Hi all,

I am using Linq to SQL and having some lengthy time problems with simple
assignment of values. At first, I thought it was a problem assigning to my
editlabels (these are a server control that will allow a label to become
an edit box... but I have eliminated that)

My linq is...

var sheet = from sheetRow in dc.ServiceSheets.Where( c =>
c.SheetID == Request.QueryString["sheet"])
join trailerRow in dc.TrailerDetails
on sheetRow.TrailerID equals trailerRow.TrailerID into
joinTable
from result in joinTable.DefaultIfEmpty()
join trailerBarcode in dc.TrailerBarcodes
on sheetRow.Barcode equals trailerBarcode.Barcode into
bcTable
from result2 in bcTable.DefaultIfEmpty()
select new
{
Sheet = sheetRow,
Trailer = result,
trBarcode = result2
};


My assignments are:

BarcodesMatch = sheet.First().trBarcode == null ? false
: (sheet.First().Sheet.Barcode == sheet.First().trBarcode.Barcode ?
(sheet.First().Sheet.TrailerID == sheet.First().trBarcode.TrailerID ? true
: false) : false);


string a1 = sheet.First().Trailer.ChassisNo;
string b1 = sheet.First().Trailer.MinistryNo;
string c1 = sheet.First().Trailer.Make;
string d1 = sheet.First().Trailer.Year;
string e1 = sheet.First().Trailer.CustomerFleetNo;
string f1 =
sheet.First().Trailer.MOTExpiry.Value.ToShortDateString();
string g1 =
sheet.First().Trailer.ODOReading.ToString();

string h1 =
sheet.First().Trailer.ServiceDue.Value.ToShortDateString();


the string a1 to h1 were being assigned to my edit labels, but it takes
just as long to assign to a string. Just this simple operation is taking
something like 5 seconds... the BarcodesMatch (which is a bool) is taking
at least 2 seconds.

I have set up indexes on my servicesheets, trailerdetails and
trailerbarcodes, though I am not sure if my indexes are correct. I have
extracted the query that the linq generates and run it direct in SSMSE and
it only takes 1 or 2 seconds.

Any ideas on what I might do next to improve the performance? (I have
other parts of the page also taking quite a bit of time, if I can get this
fixed, then perhaps the same fix will also apply elsewhere, though I know
that this area here is the biggest bottleneck)

--
Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available
 
P

Patrice

"First" does a request. So if you are repeateadly calling First then you'll
make a request each time it is called... Now Im' not sure whihc part is
still a bit slow. On the same line use SQL Profiler to check ofr uneeded
requests that could have been left out...

--
Patrice

David said:
Doh!!!

I just tried something new and it appears to work...

I noticed that each string assignment was using sheet.First().Trailer...

So, I recoded slightly...

TrailerDetail dt = sheet.First().Trailer;

string a1 = dt.ChassisNo;
string b1 = dt.MinistryNo;
string c1 = dt.Make;
string d1 = dt.Year;
string e1 = dt.CustomerFleetNo;
string f1 = dt.MOTExpiry.Value.ToShortDateString();
string g1 = dt.ODOReading.ToString();

string h1 = dt.ServiceDue.Value.ToShortDateString();

This has made quite a bit of difference, by assigning
sheet.First().Trailer then calling from that assingment.

Who'd have thunk it? I think I will now be reviewing all my code for this.

However, if you can think of other ways to speed me up a bit, it will be
appreciated.

--
Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available


David said:
Hi all,

I am using Linq to SQL and having some lengthy time problems with simple
assignment of values. At first, I thought it was a problem assigning to
my editlabels (these are a server control that will allow a label to
become an edit box... but I have eliminated that)

My linq is...

var sheet = from sheetRow in dc.ServiceSheets.Where( c =>
c.SheetID == Request.QueryString["sheet"])
join trailerRow in dc.TrailerDetails
on sheetRow.TrailerID equals trailerRow.TrailerID into
joinTable
from result in joinTable.DefaultIfEmpty()
join trailerBarcode in dc.TrailerBarcodes
on sheetRow.Barcode equals trailerBarcode.Barcode into
bcTable
from result2 in bcTable.DefaultIfEmpty()
select new
{
Sheet = sheetRow,
Trailer = result,
trBarcode = result2
};


My assignments are:

BarcodesMatch = sheet.First().trBarcode == null ?
false : (sheet.First().Sheet.Barcode == sheet.First().trBarcode.Barcode ?
(sheet.First().Sheet.TrailerID == sheet.First().trBarcode.TrailerID ?
true : false) : false);


string a1 = sheet.First().Trailer.ChassisNo;
string b1 = sheet.First().Trailer.MinistryNo;
string c1 = sheet.First().Trailer.Make;
string d1 = sheet.First().Trailer.Year;
string e1 = sheet.First().Trailer.CustomerFleetNo;
string f1 =
sheet.First().Trailer.MOTExpiry.Value.ToShortDateString();
string g1 =
sheet.First().Trailer.ODOReading.ToString();

string h1 =
sheet.First().Trailer.ServiceDue.Value.ToShortDateString();


the string a1 to h1 were being assigned to my edit labels, but it takes
just as long to assign to a string. Just this simple operation is taking
something like 5 seconds... the BarcodesMatch (which is a bool) is taking
at least 2 seconds.

I have set up indexes on my servicesheets, trailerdetails and
trailerbarcodes, though I am not sure if my indexes are correct. I have
extracted the query that the linq generates and run it direct in SSMSE
and it only takes 1 or 2 seconds.

Any ideas on what I might do next to improve the performance? (I have
other parts of the page also taking quite a bit of time, if I can get
this fixed, then perhaps the same fix will also apply elsewhere, though I
know that this area here is the biggest bottleneck)

--
Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available
 
Top