簡體   English   中英

在SharePoint 2010中使用SPMetal由LoginName(ID)創建

[英]Created By LoginName (ID) with SPMetal in SharePoint 2010

我正在使用SP2010中的OOB博客網站。 我正在使用SPMetal為Posts列表(以及其他)生成實體類。 我使用了parameters.xml文件來獲取我需要的其他默認情況下不包括的列。

我要做的一件事是獲取用戶的“我的網站” URL。 我可以使用CAML相對容易地做到這一點。 但是我需要使用Linq。 我不知道如何獲取作者字段的登錄ID(即domain \\ id)。 我已經查看了聯系人內容類型,但似乎沒有任何幫助。

有沒有人碰到過這個或獲得了SPMetal用戶的登錄ID?

如果您使用SPMetel.exe創建Posts實體列表,並且如果在“帖子”列表中具有“假設字段類型”為“用戶”,則自動返回兩個方法,如LookupId和LookupValue。

在我的情況下:我有兩個方法在我的實體中的Posts列表中將promoterid作為字段名稱

    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查詢之后

     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;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM