There is already an open DataReader associated with this Command which must be closed first.

November 18, 2009 10:25 by bryan

Having been using LINQ to SQL for some time now, I came across my very first issue "There is already an open DataReader associated with this Command which must be closed first." it's been some time since I had this issue.

The issue only appears on one database and that is being held on a SQL 2000 box.

The solution, sorry work around, is to transfer the results in to Lists using ToList() after each LINQ call.

I have found it hard to replicate in my test environment, as it only happens on a clients installation.

David Foderick posted a similar issue he had with the Entity Framework

After speaking with Eric Nelson, he pointed out that SQL 2000 has a lack of support for MARS, however there is no planning to provide support for this, however SQL Azure does not allow MARS. So perhaps this issue will get addressed some time in the future?


LINQ to XML

September 2, 2009 19:05 by bryan

Need to know how to write easy to look after XML code, check out the the DNRTV

http://perseus.franklins.net/dnrtvplayer/player.aspx?ShowNum=0147

The source code can be download here LINQXMLSamples.zip (112.26 kb)


Speed and Performance of LINQ

May 26, 2009 15:10 by bryan

I was wondering today if anyone had produced any benchmarks on the speed and performance of LINQ, so I had a look around and found that LINQ 2 SQL is 4 times faster than the Entity Framework.  Why is this?  It is due the the fact that the Entity Framework is a more generic solution, where as LINQ to SQL can be more fine tuned to the underlying database structure.

Here are a few links I found that might explain things in more details

ADO.NET Entity Framework Performance Comparison

How Slow is 'Slow'?


Tools for Linq to SQL and ADO.NET Entity Framework

May 26, 2009 09:06 by bryan

I have found LINQ to SQL and the Entity Framework has a few missing features, one of these is the ability to update the designer diagrams, and this is where Huagati DBML come to play.

Huagati DBML/EDMX Tools is an add-in for Visual Studio that adds functionality to the Linq2SQL/DBML diagram designer in Visual Studio 2008, and to the ADO.NET Entity Framework designer in Visual Studio 2008 SP1.


Finding if any records exist in a table

April 17, 2009 09:55 by bryan

When you need to find if any records exist in a table or a selective snap shot of a table, you are prehaps like me in using the COUNT(*) SQL transaction and see if there are zero counts, but is this the most efficient method?

After a performance issue on one of my applications I found a new extension to LINQ to SQL called ANY(), from Ray Booysen on StackOverflow, here is an example of the SQL that is generated from LINQ:

The Results:

SELECT COUNT(*) AS [value] FROM [dbo].[Employees] AS [t0]

9

SELECT (CASE WHEN EXISTS(SELECT NULL AS [EMPTY] FROM [dbo].[Employees] AS [t0]) THEN 1 ELSE 0 END) AS [value]

True


As you can see LINQ wins the day again.


Speed and Performance LINQ to SQL or LINQ to Entities

March 17, 2009 11:56 by bryan

What with the release of LINQ to Entities, and LINQ to SQL, which one performs better?

For comparison of performance it is worth chekcing out Eric's blog, but I still perfer LINQ to SQL.

Not that I would use the Entity Framework yet, see my article on this

 


Viewing the SQL that is generated from LINQ to SQL

March 6, 2009 11:17 by bryan

There comes a time when you are using LINQ to SQL that you just have to find out what SQL is being generated, for what ever reason that is, here a a few ways to get the SQL you are looking for:

You can use SQL Server Profile to see the traffic going to and from the database

But if you are like me you want more control over your processes, so you can use the DataContext.Log, and output the log to a window, or in the case below the console window

One last method is to just write out an objects SQL, using the GetCommand, as seen below


Bye Bye SQL Enterprise Manager

February 27, 2009 12:41 by bryan

Just found a great LINQ tool for quering any database LINQPad, is so useful I almost fell off my chair when I found it.

If you're using LINQ then this is a must on a list of tool you need to have.

When I was using it I thought it would be nice to have Autocompletion, and it does, so long as you register the product.


Entity Framework Issues

February 4, 2009 08:59 by bryan

I've come across two issues with the Entity Framework, one that effects any language and one just for VB.NET

It's quite simple, the Entity Framework generates edmx files, however that Inherits Global.System.Data.Objects.DataClasses.EntityObject, which means when you create your Partial class you can not Inherit from your own base class.

The second issue is related to VB.NET, as if you are intending to use Dependence Injection or IoC you need to have an Interface defined and to implement an Interface in VB.NET you must add Implements after each Property and Method, which you can not do as the framework generates it's own code.

I've attached both C# and VB.NET examples, none of which compile

Entity Framework Issues.zip (42.58 kb)


Creating an Entity Connection for the Entity Framework

January 23, 2009 09:18 by bryan

When you start to play with the Entity Framework you will soon come up with the need to store your connection in a common place.  To do this you will need to with provide the connection string to the Entity Object Context or provide the Entity Connection.  I prefer to us the Entity Connection as you can explicity define each section of the connection.

C#

VB.NET

and if you need to pass in the UserID and Password

For some more help on setting this up check out Ricka on Dynamic Data