Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add Linq support in SQL CLR

Tags:

linq

sqlclr

It is my understanding that System.Core.dll and System.Xml.Linq.dll are supported (or will be) in SQL server 2008.

I am trying to use Linq to Objects in my SQL 2008 CLR project.

How would I go about "adding" / registering those dlls? (I can't add them as references)

Thanks in advance, Orry

like image 604
Orry Avatar asked Mar 31 '10 17:03

Orry


People also ask

How do I get the LINQ query in SQL?

You can get same generated SQL query manually by calling ToString: string sql = committeeMember. ToString(); This overridden method internally calls ObjectQuery.

How does LINQ work with SQL?

When the application runs, LINQ to SQL translates into SQL the language-integrated queries in the object model and sends them to the database for execution. When the database returns the results, LINQ to SQL translates them back to objects that you can work with in your own programming language.

Is LINQ to SQL still used?

LINQ to SQL was the first object-relational mapping technology released by Microsoft. It works well in basic scenarios and continues to be supported in Visual Studio, but it's no longer under active development.


1 Answers

SQLCLR projects don't seem to provide the "Add reference" menu item, but Power Commands for Visual Studio at http://code.msdn.microsoft.com/PowerCommands provides an easy workaround.

1) Install the power commands.

2) Create another, non-SQLCLR project, and add those references to it. If you already have a project with those references in the solution, skip this & just use it.

3) Right click on each desired reference from #2, and select Copy reference. Go to the references node of your SQLCLR project and select Paste reference.

Note well that you cannot just reference any old DLL; there's a pretty narrow pre-approved list of allowed dlls. See e.g. http://www.sqlskills.com/blogs/bobb/post/New-SQLCLR-approved-assembly-in-SP1.aspx for more on that.

Hope this helps!

like image 77
Paul Smith Avatar answered Oct 16 '22 16:10

Paul Smith