For those of you who have used the Orcas January CTP you may have noticed a lack of Linq templates. According to the forums (http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1100902&SiteID=1) this was intentional and Linq is still included and useable.
Steps to creating a Linq project using the CTP are as follows:
- Create a new project
- Linq assemblies are then required to be referenced, they can be found here : C:WINDOWSMicrosoft.NETFrameworkv3.5.11209
The important ones are System.Core.dll, System.Data.Entity.dll, System.Data.Linq.dll and System.Xml.Linq.dll
The core is for the standard linq queries, where Data.Linq and Xml.Linq are what the old DLinq and XLinq were. - Depending on what your planning on doing, add the required references.
- The using statements are as follows for the various parts of Linq
using System.Linq;
using System.Data.DLinq; //Haven’t migrated it yet, guessing this is what will be done in February CTP and why this CTP doesn’t include much Linq to SQL
using System.Xml.Linq; - Sample code to check it all works (Linq to Objects)
int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 };
var lowNums =
from n in numbers
where n < 5
select n;Console.WriteLine(“Numbers < 5:");
foreach (var x in lowNums)
{
Console.WriteLine(x);
}Console.ReadLine();
That is how to setup Linq for a project. I will discuss Linq to SQL in another post and how you can use it with your database.
Now, back onto my degree.
Thanks so much for this info. I was beginning to wonder how to get started. This is a great start, thanks!
Thanks, I first tried to add it to a web-template on the pageload function and change Console to Response.Write().
That didnt work though, any idea why?
Had no trouble when I changed to a console application.