In this article, I do a test in WSS about using linq to read database.

What you need to do my test:
1. VS 2008 Beta2
2. Windows Server 2003 with WSS 3.0 installed
3. Sql Server 2005 or Sql Server 2005 express with Northwind database intalled.

Now, let's begin. 

1. Configure the Web.config

First, you have to install .Net Framework 3.5. Then, you have to configure the web.config of your WSS web site. Just reference the file auto-generated by VS2008 Beta 2.

 Pay attention to that: the trust level must be changed to Full.

<trust level="Full"/> 

In the compilation elements, add following assemblies.

 

 

<compilation debug="false">
Using LINQ in WSS with VS 2008 Beta 2
<assemblies>
Using LINQ in WSS with VS 2008 Beta 2        
<add assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" />
Using LINQ in WSS with VS 2008 Beta 2        
<add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
Using LINQ in WSS with VS 2008 Beta 2        
<add assembly="System.Data.DataSetExtensions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
Using LINQ in WSS with VS 2008 Beta 2        
<add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
Using LINQ in WSS with VS 2008 Beta 2        
<add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
Using LINQ in WSS with VS 2008 Beta 2
</assemblies>
</compilation>Using LINQ in WSS with VS 2008 Beta 2

 Out of the <system.web> elements, add these:

 

Using LINQ in WSS with VS 2008 Beta 2<system.codedom>
Using LINQ in WSS with VS 2008 Beta 2      
<compilers>
Using LINQ in WSS with VS 2008 Beta 2         
<compiler language="c#;cs;csharp" extension=".cs" compilerOptions="/warnaserror-" warningLevel="4" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
Using LINQ in WSS with VS 2008 Beta 2             
<providerOption name="CompilerVersion" value="v3.5"/>
            
</compiler>
Using LINQ in WSS with VS 2008 Beta 2         
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" compilerOptions="/optioninfer+" type="Microsoft.VisualBasic.VBCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">Using LINQ in WSS with VS 2008 Beta 2
Using LINQ in WSS with VS 2008 Beta 2              
<providerOption name="CompilerVersion" value="v3.5"/>
  Using LINQ in WSS with VS 2008 Beta 2        
</compiler>
Using LINQ in WSS with VS 2008 Beta 2      
</compilers>
  
</system.codedom>

 2. Creating a C# class library project. In the project setting page, signing this project.

 Using LINQ in WSS with VS 2008 Beta 2

3. Create a LINQ Northwind Context, reference the Scott Gu' blog about how to to it.

http://weblogs.asp.net/scottgu/archive/2007/05/29/linq-to-sql-part-2-defining-our-data-model-classes.aspx

4.Create a class which inherit from
System.Web.UI.WebControls.WebParts.WebPart

 

Using LINQ in WSS with VS 2008 Beta 2using System;
Using LINQ in WSS with VS 2008 Beta 2
using System.Collections.Generic;
Using LINQ in WSS with VS 2008 Beta 2
using System.Linq;
Using LINQ in WSS with VS 2008 Beta 2
using System.Text;
Using LINQ in WSS with VS 2008 Beta 2
using System.Web.UI;
Using LINQ in WSS with VS 2008 Beta 2
using System.Web.UI.WebControls.WebParts;
Using LINQ in WSS with VS 2008 Beta 2
using System.Web.UI.WebControls;
Using LINQ in WSS with VS 2008 Beta 2
using System.Xml.Serialization;
Using LINQ in WSS with VS 2008 Beta 2
Using LINQ in WSS with VS 2008 Beta 2
using Microsoft.SharePoint;
Using LINQ in WSS with VS 2008 Beta 2
using Microsoft.SharePoint.WebControls;
Using LINQ in WSS with VS 2008 Beta 2
using Microsoft.SharePoint.WebPartPages;
Using LINQ in WSS with VS 2008 Beta 2
Using LINQ in WSS with VS 2008 Beta 2
namespace GlenCode

5. Build the Project. Put the dll into the bin of the WSS extended Web.

6.In the webpart gallary of the site collection, populate the webpart.

7.Add the webpart to one of your web page.

相关文章: