S
shapper
Hello,
I have 3 tables: Posts, Tags and PostsTags.
PostsTags relates Posts with Tags and has 3 fields: PostID and TagID.
I have all the relationships between tables well defined!
I have the following query:
PostPaper paper = (from p in database.Posts
where p.PostID == id
select new PostPaper {
Post = p,
Tags = new List<Tag>(
from pt in database.PostsTags
join t in database.Tags on pt.TagID
equals t.TagID
where pt.PostID == p.PostID
select t).ToString()
}).SingleOrDefault();
Can I replace the Tags part with some linq code without using join?
For example:
...
Post = p,
Tags = p.PostsTags.
Maybe use SelectMany?
Please, help me out in understanding this.
Thanks,
Miguel
I have 3 tables: Posts, Tags and PostsTags.
PostsTags relates Posts with Tags and has 3 fields: PostID and TagID.
I have all the relationships between tables well defined!
I have the following query:
PostPaper paper = (from p in database.Posts
where p.PostID == id
select new PostPaper {
Post = p,
Tags = new List<Tag>(
from pt in database.PostsTags
join t in database.Tags on pt.TagID
equals t.TagID
where pt.PostID == p.PostID
select t).ToString()
}).SingleOrDefault();
Can I replace the Tags part with some linq code without using join?
For example:
...
Post = p,
Tags = p.PostsTags.
Maybe use SelectMany?
Please, help me out in understanding this.
Thanks,
Miguel