0

我正在使用 SP2010 中的 OOB 博客站点。我正在使用 SPMetal 为 Posts 列表(以及其他)生成实体类。我使用了 parameters.xml 文件来获取我需要的其他默认情况下不包含的列。

我想做的一件事是获取用户的“我的网站”网址。我可以相对容易地使用 CAML 做到这一点。但是我需要使用 Linq 来完成。我不知道如何获取作者字段的登录 ID(即域\ID)。我查看了联系人内容类型,但似乎没有任何帮助。

有没有人遇到过这个问题或获得了 SPMetal 用户的登录 ID?

4

1 回答 1

0

如果您使用创建Posts列表实体SPMetel.exe并且如果在帖子列表中假设字段类型为用户,则自动返回两种方法,如 LookupId 和 LookupValue。

在我的情况下:我在我的实体promoterid中的列表中作为字段名称有两种方法Posts

    private System.Nullable<int> _promoterId;
    private string _promoter;
    [Microsoft.SharePoint.Linq.ColumnAttribute(Name="promoterid", Storage="_promoterId", FieldType="User", IsLookupId=true)]
    public System.Nullable<int> PromoterId {
    get {
        return this._promoterId;
    }
    set {
        if ((value != this._promoterId)) {
            this.OnPropertyChanging("PromoterId", this._promoterId);
            this._promoterId = value;
            this.OnPropertyChanged("PromoterId");
        }
    }
}

[Microsoft.SharePoint.Linq.ColumnAttribute(Name="promoterid", Storage="_promoter", ReadOnly=true, FieldType="User", IsLookupValue=true)]
public string Promoter {
    get {
        return this._promoter;
    }
    set {
        if ((value != this._promoter)) {
            this.OnPropertyChanging("Promoter", this._promoter);
            this._promoter = value;
            this.OnPropertyChanged("Promoter");
        }
    }
}

比我可以使用 linq 查询之后

IE

     SPWeb oWebsiteRoot = SPContext.Current.Web;
     EntitiesDataContext objent = new EntitiesDataContext(oWebsiteRoot.Url);
     EntityList<PostsItem> evnitems = objent.GetList<PostsItem>("Posts");
     var i =  from item in evnitems
              where item.PromoterId == SPContext.Current.Web.CurrentUser.ID 
             select item;
于 2012-06-07T17:38:43.583 回答