简体   繁体   中英

Created By LoginName (ID) with SPMetal in SharePoint 2010

I'm working with the OOB blog sites in SP2010. I'm using SPMetal to generate entity classes for the Posts list (among others). I've used a parameters.xml file to get the other columns that I need that aren't included by default.

One of the things that I want to do is to get the users' My Site url. I am able to do this with CAML relatively easily. However I need to do it using Linq. I can't figure out how to get the login id (ie domain\\id) for the Author Field. I've looked through the Contact content type and it doesn't appear to have anything to help.

Has anyone run across this or gotten the login id for a user with SPMetal?

if you create Entity of Posts list using SPMetel.exe and if in Posts list having Suppose Field Type is User than automatically return two methods of like LookupId and LookupValue.

In my case : I have take promoterid As a Field name in Posts list in in my Entity having two method

    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");
        }
    }
}

than after i can able to use using linq query

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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM