首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >亚音速3.0和“链接”表

亚音速3.0和“链接”表
EN

Stack Overflow用户
提问于 2010-01-23 12:24:48
回答 2查看 171关注 0票数 0

我有下面的安排。

BlogPosts BlogToCategory范畴

一个博客帖子可以有很多分类,一个类别可以在很多博客文章中。(因此是中间表。

我怎样才能得到所有博客的列表--一个类别的帖子。

我试过了,但似乎做不到(我得到了一个IQueryable -> IEnumerable强制转换错误)

代码语言:javascript
复制
public IEnumerable<BlogPost> FetchAllBlogs(int? CatId)
{
        return from c in CategoryLink.All()
                   where c.CategoryID == CatId
                   select c.BlogPost;

}

好的,如下所示,我已经尝试了以下几种方法。

代码语言:javascript
复制
return from blogToCategories in subtext_Link.All()
                      join blogPosts in subtext_Content.All() on blogToCategories.BlogId equals blogPosts.BlogId
                      where blogToCategories.CategoryID == CatId
                      orderby (blogPosts.DateAdded) descending
                      select blogPosts;

现在,这似乎是错误的连接,因为每当链接表中有一些数据(表链接类别到博客),它就会返回所有博客。

也尝试了下面的方法。

代码语言:javascript
复制
BlogList = new TransformDB().Select
                  .From<subtext_Content>()
                  .InnerJoin<subtext_Link>(subtext_LinksTable.BlogIdColumn, subtext_ContentTable.BlogIdColumn)
                  .Where(subtext_LinksTable.CategoryIDColumn).IsEqualTo(CatId)
                  .ExecuteTypedList<subtext_Content>();

生成SQL

选择dbo.subtext_Links.LinkID,dbo.subtext_Links.Title,dbo.subtext_Links.Url,dbo.subtext_Links.Rss,dbo.subtext_Links.Active,dbo.subtext_Links.CategoryID,dbo.subtext_Links.BlogId,dbo.subtext_Links.PostID,dbo.subtext_Links.NewWindow,dbo.subtext_Links.Rel,\r\ndbo.subtext_Content.ID,dbo.subtext_Content.Title,dbo.subtext_Content.DateAddeddbo.subtext_Content.PostType,dbo.subtext_Content.Author,dbo.subtext_Content.Email,dbo.subtext_Content.BlogId,dbo.subtext_Content.Description,dbo.subtext_Content.DateUpdated,dbo.subtext_Content.Text,dbo.subtext_Content.FeedBackCount,dbo.subtext_Content.PostConfig,dbo.subtext_Content.EntryNamedbo.subtext_Content.DateSyndicated\r\n从dbo.subtext_Links\r\n内部加入dbo.subtext_Content ON dbo.subtext_Links.BlogId = dbo.subtext_Content.BlogId\r\n,其中dbo.subtext_Links.CategoryID = @0"

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2010-01-23 12:44:07

您需要加入BlotToCategory和BlogPost表:

代码语言:javascript
复制
public IEnumerable<BlogPost> FetchAllBlogs(int? CatId)
{
  return from blogToCategories in BlogToCategory.All() 
         join blogPosts in BlogPost.All() on blogPosts.Id equals blogToCategories.BlogId 
         where blogToCategories.CategoryID == CatId
         select blogPosts;

}
票数 1
EN

Stack Overflow用户

发布于 2010-01-23 13:51:25

我试过了,但似乎做错了(我得到了一个IQueryable -> IEnumerable强制转换错误)

如何使用.ToList()方法?

http://msdn.microsoft.com/en-us/library/bb342261.aspx

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/2123113

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档