你能让这个多对多脚本更加动态吗?
这只是我建立多对多关系的简单方法,但我想要一些可以轻松创建多对多关系的方法,我希望我可以创建一个方法返回类型匿名,这将打开一些大门。但我不擅长匿名类型,但是!
希望您能帮忙!
当你需要的时候,你们会做什么
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;
}
这很愚蠢吗?
This is just my simple way of making a many to many relationship, but i would like something that makes it easy to create many to many, I have wished i could make a method return type anonymous, that would open some doors. But i am noot good with anonymous types, Yet!
Hope you can help !
What do you guys do when you need
private class Ids
{
public int Id;
}
.
...
. And in some method:
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: I Used your code like this:
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;
}
Is that stupid?
我所做的是:
What I do is: