使用SPMetal实体类

时间:2010-12-01 12:20:58

标签: linq sharepoint sharepoint-2010

我正在执行以下代码,以通过LINQ获取有关网页的信息。它工作正常,但我如何转换它并使用SPMetal命令生成的实体类?

Guid siteGuid = SPContext.Current.Site.ID;
using (SPSite site = new SPSite(siteGuid))
{
    using (SPWeb web = site.OpenWeb())
    {
        SPList lespages = web.Lists["Pages"];

        var resultat = from SPListItem page
                       in lespages.Items
                       where page.ContentType.Name.Equals("PageNews") && page.ModerationInformation.Status.Equals(SPModerationStatusType.Approved)
                       select page;

        foreach (SPListItem r in resultat)
        {
            contenu += "_ModerationStatus: " + r["_ModerationStatus"] + "<br>";
            contenu += "FileLeafRef: " + r["FileLeafRef"] + "<br>";
            contenu += "PublishingPageContent: " + r["PublishingPageContent"] + "<br>";
            contenu += "ContentType: " + r["ContentType"] + "<br>";
            contenu += "Categorie: " + r["Categorie"] + "<br>";
        }
        PanelResultat.Controls.Add(new LiteralControl(contenu));
    }
}

1 个答案:

答案 0 :(得分:2)

使用以下链接为您提供帮助

1.SP Metal Code

2. SPMetal Tutorial