Solved

linq groupjoin using lambda with a where clause

Posted on 2013-01-13
4
702 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How do I partition this table on date? 5 49
SQL Query Works in SQL 2008 & 2012 But Not SQL 2016 15 98
Sending HTML Formatted Email from ASP.NET 2 50
history of pages 7 48
I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…
Suggested Courses

738 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