views:

109

answers:

2

I'm using visual studio 2008. How can i use linqtosql on the sql server project?

+1  A: 

The sql server project type is for managing DB objects, it is not a coding language project type.

http://msdn.microsoft.com/en-us/library/c8dbfz8s.aspx

If you want to use LinqToSql to connect to a database you must use a language specific project like C# or VB.NET.

keithwarren7
But i found this project http://www.codeproject.com/KB/database/SqlRegularExpressions.aspx . this use regular expression. This how can work? I don't understand
ebattulga
That is using a new type of object introduced in SQL 2005 called a CLR Stored Procedure.
keithwarren7
A: 

It's not clear exactly what you're asking for help with. But let's start with this:

  1. Start Visual Studio 2008.
  2. Select New Project->Visual C#->Windows->Empty Project.
  3. Right click on the project in Solution Explorer->Add New Item->Visual C# Items->Data->LINQ to SQL classes. Double click the newly added dbml file to open it in the main window.
  4. View->Server Explorer->Right click Data Connections->Add Connection.
  5. Key in the connection parameters to your database.
  6. In Server Explorer expand the server you just added->expand tables->left click and drag one of your database tables to the main window (the designer surface).

Presto, you have now created your first LINQ to SQL-enalbed DataContext.

Jason
how to use linq on "SQL SERVER PROJECT". I know use linq on simple c# project
ebattulga
Repeating yourself and shouting at me isn't going to make it more likely that I continue to try to help you. I stated that it was not clear what you are asking for and made an earnest effort to help you. Please clarify what you're trying to do.
Jason
I'm creating stored procedure using SQL SERVER PROJECT. When i create stored procedure, i need to use linq. My question is, it is possible to use linq on this stored procedure
ebattulga
No. SQL Server Projects are for creating and manipulating CLR SQL Server objects (stored procedures, user-defined types, aggregates, etc.) That is, they are for using .NET inside SQL Server. As far as I know, LINQ-to-SQL will not work in this scenario at least not in SAFE mode as `System.Data.Linq` is not in the approved list of assemblies. At best you could try in UNSAFE mode, but I'm not even sure about that.
Jason
This thread on MSDN forums seems to confirm what I am saying: http://social.msdn.microsoft.com/forums/en-US/sqlnetfx/thread/a553dfad-9fe2-42ab-a46a-be66760249cf/
Jason