Sharepoint2010如何使用Linq to Sharepoint

Sharepoint2010如何使用Linq to Sharepoint

1、 在http://moss:8002创建了列表如下图所示:

Sharepoint2010如何使用Linq to Sharepoint_第1张图片

2、 使用

SPMetal /web:http://ContosoServer/Marketing /code:MarketingSite.cs /language:csharp

这里采用:

SPMetal /web:http://moss:8002/ /code:c:\Moss2010Entities.cs /language:csharp

3、 运行CMD,输入如下:

Sharepoint2010如何使用Linq to Sharepoint_第2张图片

在C盘根目录下得到类:Moss2010Entities.cs

4、 打开VS2010创建Webpart解决方案,如图:

Sharepoint2010如何使用Linq to Sharepoint_第3张图片

5、 C#应用程序引用Microsoft.SharePoint.Linq.dll,位置位于:C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\ISAPI\Microsoft.SharePoint.Linq.dll

Sharepoint2010如何使用Linq to Sharepoint_第4张图片

6、 添加刚创建的类添加刚才创建的类Moss2010Entities.cs到已经存在的项目里来

Sharepoint2010如何使用Linq to Sharepoint_第5张图片

7、 引用下面2个命名空间,如下图:

Sharepoint2010如何使用Linq to Sharepoint_第6张图片

8、 编码如下:

Sharepoint2010如何使用Linq to Sharepoint_第7张图片

9、 发布预览得到如下结果:

Sharepoint2010如何使用Linq to Sharepoint_第8张图片

你可能感兴趣的:(SharePoint)