Using System.Linq assembly in SQL CLR UDF

2019-04-20 23:46发布

问题:

I am creating a SQL Server user-defined function in C# using the SQL UDF project type in Visual Studio 2010. I have a simple Linq string manipulation expression (myString.Where()) in my code that generates an error because I'm not using the System.Linq namespace. If I add

using System.Linq;

to my .cs file, I get an error asking me if I'm missing an assembly reference. If I then right-click the project in Solution Explorer, and select "Add Reference", there is no System.Linq component listed in the .NET tab.

I suppose I could go browsing the hard drive for the appropriate assembly DLL, but why doesn't Visual Studio know about it? Is there some restriction about using Linq in SQL CLR code?

回答1:

Okay, apparently adding a reference to System.Core.DLL to the project will allow the "using System.Linq" statement to compile in a SQL CLR project. Go figure.