How would this Linq query with Join be written as a Lambda?

entity-framework-6 lambda vb.net

Question

I have this linq query and am attempting to learn how to make joins as lambdas, but I am at a loss as to how to do it.

From posts In db.be_Posts Join t In db.be_PostTag On posts.PostID 
Equals t.PostID Where t.Tag = tag Select posts.Title

LinqPad supports the Join mentioned above. And the lambda I currently have is this. Furthermore, I'm attempting to fit everything inside the viewmodel.

db.be_Posts.OrderByDescending(Function(x) x.DateCreated).Join(db.be_PostTag, 
Function(p) p.PostID, Function(t) t.PostID, Function(p, t).Select(Function(p1) 
New be_PostsViewModel
With {.Id = 

After that, I don't obtain an intelligence.Id when I press the p, p1, or t key. Why am I mishandling this? Many thanks

1
2
7/3/2017 12:45:54 PM

Accepted Answer

(Is it an error or was this part meant to seem weird?) :

....Function(p, t).Select(Function(p1)...

As best as I can tell, something like this should function:

db.be_Posts.
    OrderByDescending(Function(x) x.DateCreated).
    Join(db.be_PostTag, _
            Function(p) p.PostID, _
            Function(t) t.PostID, _
            Function(p, t) New be_PostsViewModel With 
                            {
                                .Id = p.PostID,
                                ....
                                ....
                            })

Additionally, the following LINQ query syntax can be converted to method syntax:

db.be_Posts.
    Join(db.be_PostTag, _
            Function(p) p.PostID, _
            Function(t) t.PostID, _
            Function(p, t) p.Title)
4
7/24/2014 4:05:02 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow