views:

60

answers:

0

Hi, does anybody know if it's possible (and how) to use LINQ on a DataTable inside a CLR Stored Procedure?

I have no problems using LINQ on a DataTable in a standard WinForms proj however; I'm using a Database Project in VS2010 on SQL2005 and creating a Stored Procedure:

(simplified listing)

[Microsoft.SqlServer.Server.SqlProcedure]
public static void ProcessReOrder()
{       
    using (SqlConnection conn = new SqlConnection("context connection=true")) { 
        SqlDataAdapter adapter = new SqlDataAdapter("database.dbo.OtherSp", conn);  
        DataTable table = new DataTable("ReOrder");
        adapter.Fill(table);

        var query = from t in table.AsEnumerable() 
                    where t.Field<int>("Id") > 1000 select t.Field<int>("Id");

    etc.....
}

The problem is, AsEnumerable() is an extension method and although I've got the using reference to LINQ; it still isn't found.

Searching Google, has lead me to believe this is to do with using an LINQ Entity reference (DLL) buried in the framework however, as this is a DB Project, we don't get to add references to any DLL on the system; the add reference box is restricted to a select few assemblies and there isn't a browse... button.

Regardless of performance issues etc, I don't want to hand roll a lot of ADO/T-SQL inside my .NET Stored proc; i prefer LINQ and the ability to move the code to different layers/DB Platforms. Is LINQ on a DataTable inside a Stored Proc supported (i guessing not) or am I completely off base here and must code with T-SQL?

Regards,

Alan.