SELECT TOP (100) PERCENT dbo.PostAdditional.Description, dbo.PostAdditional.Summary, dbo.PostAdditional.Title, dbo.Post.PostID, dbo.Post.Type, dbo.Tags.TagID, dbo.Tags.TagName,
FROM dbo.Post
INNER JOIN dbo.PostAdditional ON dbo.Post.PostID = dbo.PostAdditional.PostID
INNER JOIN dbo.PostWithTags ON dbo.Post.EventID = dbo.PostWithTags.PostID
INNER JOIN dbo.Tags ON dbo.PostWithTags.TagID = dbo.Tags.TagID
ORDER BY dbo.Post.StartDate, dbo.Post.PubDate
我想使用LINQ to SQL来处理它。当我正式将此视图放在DBML设计器中时,它会创建一个实体。但实体将tagName保护为String,我想将它作为标记名称数组(或更好的List<>)。当我从数据库中获取数据时,我获得了一个用于evry单个标记的Post实体的副本,但是我希望得到一个Post实体,其中包含所有标记的数组。
答案 0 :(得分:1)
也许这会有所帮助: 我从
改变了这个联接INNER JOIN dbo.PostWithTags ON dbo.Post.EventID = dbo.PostWithTags.PostID
要
INNER JOIN dbo.PostWithTags ON dbo.Post.PostID = dbo.PostWithTags.PostID
如果我理解你,这就是你想要的吗?
var test=
(
from p in db.Post
orderby p.StartDate,p.PubDate
select new
{
p.PostID,
p.Type,
Tags=
(
from pa in db.PostAdditional
join pwt in db.PostWithTags
on pa.PostID equals pwt.PostID
join t in db.Tags
on pwt.TagID equals t.TagID
where p.PostID == pa.PostID
select new
{
pa.Description,
pa.Summary,
pa.Title,
t.TagID,
t.TagName
}
)
}
).ToList();
其中db是databasecontext