LINQ to SharePoint-算在子查询中吗? [英] LINQ to SharePoint - Count in subquery?
问题描述
你好
我正在使用SP 2010的Web部件,并且需要使用LINQ to SP来查询SharePoint列表.
该列表具有3种内容类型(论坛,主题和帖子).
我要做的是检索所有论坛名称和每个论坛中的主题数.
到目前为止,这是我的代码:
DataContext数据=新的DataContext(SPContext.Current.Web.Url);
//获取SharePoint列表
EntityList< BO.ForumStorageInstanceForum>论坛= data.GetList< BO.ForumStorageInstanceForum>("ForumStorageInstance");
EntityList< BO.ForumStorageInstanceThread>线程= data.GetList< BO.ForumStorageInstanceThread>("ForumStorageInstance");
var allForums =来自论坛中的论坛
选择新的{
forumId = forum.ForumId,
标题=论坛.标题,
留言=论坛.留言,
threadCount =(int)(来自Threads中的线程
其中thread.ForumId == forum.ForumId
选择线程).Count()
};
BO是使用SPMetal创建的,但它们未在LINQ(与LINQ to SQL中的父子关系)中链接,只有ForumId链接了它们.
此代码可以编译,但会引发异常.我能解决的是我的实体是关系型的,并且直接链接到类似
的位置 var allForums =来自论坛中的论坛
选择新的{
forumId = forum.ForumId,
标题=论坛.标题,
留言=论坛.留言,
threadCount =(int)(来自论坛中的线程
其中thread.ForumId == forum.ForumId
选择线程).Count()
};
但是它们不是...任何解决方案?
罗伯特你好,
欢迎来到MSDN论坛!
您能告诉我们您收到什么例外吗? =">
此外,根据我的理解,您可以尝试以下查询吗? ?
=============== ================================================== ========================
var allForums =来自论坛中的论坛
b ; {
b ; Message = forum.Message,
b ; 选择线程).Count()
=============== ================================================== ========================
早上好!
最好的问候,
孙灵芝MSDN订户支持 在论坛中
如果您对我们的支持有任何反馈,请联系 msdnmg@microsoft.com
>
Hello,
I am working on a webpart for SP 2010 and I need to use LINQ to SP to query a SharePoint List.
The list has 3 content types (Forum, Thread and Post).
What I want to do is to retrieve all the forums names and the number of thread in each of them.
Here is my code so far:
DataContext data = new DataContext(SPContext.Current.Web.Url);
// Get the SharePoint list
EntityList<BO.ForumStorageInstanceForum> Forums = data.GetList<BO.ForumStorageInstanceForum>("ForumStorageInstance");
EntityList<BO.ForumStorageInstanceThread> Threads = data.GetList<BO.ForumStorageInstanceThread>("ForumStorageInstance");
var allForums = from forum in Forums
select new {
forumId = forum.ForumId,
Title = forum.Title,
Message = forum.Message,
threadCount = (int)(from thread in Threads
where thread.ForumId == forum.ForumId
select thread).Count()
};
The BO have been created using SPMetal but they are not linked in LINQ (parent-child relation as in LINQ to SQL), only the ForumId links them.
This code compiles but throws an exception. I could solve this is my entities were relational and linked directly something like
var allForums = from forum in Forums
select new {
forumId = forum.ForumId,
Title = forum.Title,
Message = forum.Message,
threadCount = (int)(from thread in forum.Threads
where thread.ForumId == forum.ForumId
select thread).Count()
};
but they are not... Any solutions?
Hello Robert,
Welcome to MSDN forums!
Could you please tell us what exception do you receive?
Besides, based on my understanding, could you try the following query instead?
=========================================================================================
var allForums = from forum in Forums
select new
{forumId = forum.ForumId,
Title = forum.Title,
Message = forum.Message,
threadCount = (int)(from thread in Threads
where thread.ForumId == forum.ForumId
select thread).Count()
};
=========================================================================================
Good day!
Best Regards,
Lingzhi SunMSDN Subscriber Support in Forum
If you have any feedback on our support, please contact msdnmg@microsoft.com
这篇关于LINQ to SharePoint-算在子查询中吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!