这只是我建立多对多关系的简单方法,但是我希望能够轻松创建多对多的关系,我希望我可以创建一个方法返回类型匿名,这将打开一些门。但我对匿名类型不太好,但是!
希望你能帮忙!
你们需要时做什么
private class Ids
{
public int Id;
}
...
。在某种方法中:
IList<Ids> objIds = new List<Ids>();
var q = from c in dt.FK_Tags_Blogs
where c.BlogId == someId
select c.TagId;
foreach (var item in q)
{
objIds.Add(new Ids { Id = item });
}
var w = from c in objIds
join p in dt.Tags on c.Id equals p.Id
select p;
David B:我使用了这样的代码:
public static IQueryable<Tag> printTags(int id)
{
DataClassesDataContext dt = new DataClassesDataContext();
return
from b in dt.Blogs
where b.Id == id
from xr in b.FK_Tags_Blogs
select xr.Tag;
}
这是愚蠢的吗?
答案 0 :(得分:0)
我的工作是:
//linq to objects
IEnumerable<Tag> tags =
from c in dt.FK_Tags_Blogs
where c.BlogId == someId
join p in dt.Tags on c.TagId equals p.Id
select p;
//linq to sql with association properties
IQueryable<Tag> tagsQuery =
from b in dc.Blogs
where b.BlogId == someId
from xr in b.FK_Tags_Blogs
select xr.Tag;