[英]Sharepoint 2010 listitem to linq 2 sharepoint spmetal class
[英]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.