简体   繁体   English

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

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

I'm working with the OOB blog sites in SP2010. 我正在使用SP2010中的OOB博客网站。 I'm using SPMetal to generate entity classes for the Posts list (among others). 我正在使用SPMetal为Posts列表(以及其他)生成实体类。 I've used a parameters.xml file to get the other columns that I need that aren't included by default. 我使用了parameters.xml文件来获取我需要的其他默认情况下不包括的列。

One of the things that I want to do is to get the users' My Site url. 我要做的一件事是获取用户的“我的网站” URL。 I am able to do this with CAML relatively easily. 我可以使用CAML相对容易地做到这一点。 However I need to do it using Linq. 但是我需要使用Linq。 I can't figure out how to get the login id (ie domain\\id) for the Author Field. 我不知道如何获取作者字段的登录ID(即domain \\ id)。 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? 有没有人碰到过这个或获得了SPMetal用户的登录ID?

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. 如果您使用SPMetel.exe创建Posts实体列表,并且如果在“帖子”列表中具有“假设字段类型”为“用户”,则自动返回两个方法,如LookupId和LookupValue。

In my case : I have take promoterid As a Field name in Posts list in in my Entity having two method 在我的情况下:我有两个方法在我的实体中的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");
        }
    }
}

than after i can able to use using linq query 比我可以使用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;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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