Solved

linq groupjoin using lambda with a where clause

Posted on 2013-01-13
4
710 Views
Last Modified: 2013-11-05
I need to add a join using Lambda if I have a further parameter available that will also be used in a where clause.

This is my original linq code, it works just fine...

    var tagList =   from t in dc.Tags
    join b in dc.Businesses on t.BusinessId equals b.BusinessId
            where t.IsActive == true
            where b.IsActive == true
            orderby t.AdImage descending
            select new TagItem
            {
                    tagName = t.Name.Replace("\"", ""),
                    tagImage = tagImagePath + t.AdImage.Replace("\"", ""),
                    tagDescription = t.Description.Replace("\"", "")
            };

My problem is I'm not sure of the exact format for adding a new object [table] MemberTagLysts using Lambda and then how the where clause should be created when I have a lystId available...

This is not quite right....

            if (!string.IsNullOrEmpty(lystId))
            {
                            tagList = (IQueryable<TagItem>)tagList.GroupJoin(dc.MemberTagLysts, a => a.tagId, b => b.TagId, (a, b) => new { a, b });
            }
0
Comment
Question by:Rob Gaudet
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 42

Expert Comment

by:sedgwick
ID: 38774007
can u explain what kind of join you wish to apply with MemberTagLysts table?
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 38774017
first u need to add tagId in your initial linq query:
.
.
.select new TagItem
            {
tagId = t.tagId,
                    tagName = t.Name.Replace("\"", ""),
                    tagImage = tagImagePath + t.AdImage.Replace("\"", ""),
                    tagDescription = t.Description.Replace("\"", "")
            };

Open in new window


now try run this:
   tagList = (IQueryable<TagItem>)tagList.GroupJoin(dc.MemberTagLysts, a => a.tagId, b => b.TagId, (a, b) => new { a, b });

Open in new window

0
 

Author Comment

by:Rob Gaudet
ID: 38779233
Sorry, tagid was in the initial query, I shortened the values to save space and pulled it out..

Your suggestion...

tagList = (IQueryable<TagItem>)tagList.GroupJoin(dc.MemberTagLysts, a => a.tagId, b => b.TagId, (a, b) => new { a, b });

....returned this error.

Unable to cast object of type 'System.Data.Linq.DataQuery`1[<>f__AnonymousType6`2[TagItem,System.Collections.Generic.IEnumerable`1[MemberTagLyst]]]' to type 'System.Linq.IQueryable`1[TagItem]'.
0
 
LVL 42

Accepted Solution

by:
sedgwick earned 500 total points
ID: 38779580
just
var group = tagList.GroupJoin(dc.MemberTagLysts, a => a.tagId, b => b.TagId, (a, b) => new { a, b });

Open in new window

0

Featured Post

Monthly Recap

May was a big month for new releases from Linux Academy! Take a look at what our team built recently in our blog. You can access the newest releases from our blog.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question