public long GetNewCRN()
{
return ((from c in DataContext.GetTable<Cust_Master>()
select c.CUSTSERH_CRN).Max() + 1);
}
Will this Linq to Sql query fetch all records from the table first and then select the maximum of the column ?
If yes, then isn’t it a bad idea using linq to sql instead of normal SqlCommand ?
Or is there any other way of doing it in linq to sql ?
When I attach Console.Out, I see nothing(command prompt does not even open).
But when I include following:-
context.Log = new System.IO.StreamWriter("d:\\abcd.txt");
I get an error, that “The process can not access the file because it is being used by another process” and that process is “w3wp.exe”.
How can I see the sql commands being executed by DataContext then ?
No this shouldn’t fetch all rows. You are only requesting the maximum value. This should be converted to an SQL query like the following:
You can verify that this is the case by attaching a logger to the DataContext before you execute the command, for example: