Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 962443
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T01:30:25+00:00 2026-05-16T01:30:25+00:00

This is the SQL query I am trying to write with LINQ: SELECT pd.Description,

  • 0

This is the SQL query I am trying to write with LINQ:

SELECT pd.Description, pd.Name, pd.SKU, pt.FileName,
(SELECT ISNULL(M1.parent, '') + '/' + M2.parent + '/' + M2.slug
    FROM seo AS M1
    JOIN seo AS M2
    ON M1.Slug = M2.Parent
    WHERE M2.SeoId = pd.seoId) as Url
FROM SEO seo
INNER JOIN Products p on seo.SeoID = p.SeoID
INNER JOIN RelatedProducts rp on p.ProductID = rp.ProductID
INNER JOIN Products pd on rp.RelatedID = pd.ProductID
INNER JOIN ProductPhotos pp on pd.ProductID = pp.ProductID
INNER JOIN Photos pt on pp.PhotoID = pt.PhotoID
WHERE seo.slug = 'SlugValue'

This is the LINQ I have:

_database.SEODataSource
                .Join(_database.ProductDataSource, seo => seo.SeoID, p => p.SeoID, (seo, p) => new { seo, p })
                .Join(_database.RelatedProductDataSource, @t => @t.p.ProductID, rp => rp.ProductID, (@t, rp) => new { @t, rp })
                .Join(_database.ProductDataSource, @t => @t.rp.RelatedID, pd => pd.ProductID, (@t, pd) => new { @t, pd })
                .Join(_database.ProductPhotoDataSource, @t => @t.pd.ProductID, pp => pp.ProductID, (@t, pp) => new { @t, pp })
                .Join(_database.PhotoDataSource, @t => @t.pp.PhotoID, pds => pds.PhotoID, (@t, pds) => new { @t, pds })
                .Where(@t => @t.@t.@t.@t.@t.seo.Slug == slug)
                .Select(@t => new ProductLinkDTO
                {
                    ProductDesc = @t.@t.@t.pd.Description,
                    ProductName = @t.@t.@t.pd.Name,
                    ProductSku = @t.@t.@t.pd.SKU,
                    ProductImageName = @t.pds.FileName,
                    ProductUrl =  (_database.SEODataSource.Join(_database.SEODataSource, seo1 => seo1.SeoID, seo2 => seo2.SeoID, (seo1, seo2) => new {seo1, seo2})
                                  .Where(@t1 => @t1.seo2.SeoID == @t.@t.@t.@t.@t.seo.SeoID)
                                  .Select(@t1 => @t1.seo1.Parent ?? "" + "/" + @t1.seo2.Parent + "/" + @t1.seo2.Slug)).FirstOrDefault()
                }).ToList());

This is the query it produces:

SELECT [t3].[Name] AS [ProductName], [t3].[Description] AS [ProductDesc], [t3].[SKU] AS [ProductSku], [t5].[FileName] 
AS [ProductImageName], (
    SELECT TOP (1) [t8].[value]
    FROM (
        SELECT COALESCE([t6].[Parent],((@p1 + [t7].[Parent]) + @p2) + [t7].[Slug]) AS [value], [t7].[SeoID]
        FROM [dbo].[SEO] AS [t6]
        INNER JOIN [dbo].[SEO] AS [t7] ON [t6].[SeoID] = [t7].[SeoID]
        ) AS [t8]
    WHERE [t8].[SeoID] = [t0].[SeoID]
    ) AS [ProductUrl]
FROM [dbo].[SEO] AS [t0]
INNER JOIN [dbo].[Products] AS [t1] ON ([t0].[SeoID]) = [t1].[SeoID]
INNER JOIN [dbo].[RelatedProducts] AS [t2] ON [t1].[ProductID] = [t2].[ProductID]
INNER JOIN [dbo].[Products] AS [t3] ON [t2].[RelatedID] = [t3].[ProductID]
INNER JOIN [dbo].[ProductPhotos] AS [t4] ON [t3].[ProductID] = [t4].[ProductID]
INNER JOIN [dbo].[Photos] AS [t5] ON [t4].[PhotoID] = [t5].[PhotoID]
WHERE [t0].[Slug] = @p0',N'@p0 nvarchar(4000),@p1 nvarchar(4000),@p2 
nvarchar(4000)',@p0=N'KBUIT4255E-42in-Masterpiece-Side-By-Side',@p1=N'/',@p2=N'/'

Any idea what I am doing wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T01:30:26+00:00Added an answer on May 16, 2026 at 1:30 am

    By changing this:

    .Select(@t1 => @t1.seo1.Parent ?? "" + "/" + @t1.seo2.Parent + "/" + @t1.seo2.Slug)).FirstOrDefault()
    

    To:

    .Select(@t1 =>  String.Concat(@t1.seo1.Parent ?? "", "/", @t1.seo2.Parent, "/", @t1.seo2.Slug))).SingleOrDefault()
    

    The correct SQL was generated.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 494k
  • Answers 494k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Regex is not the best tool of the job, but… May 16, 2026 at 10:56 am
  • Editorial Team
    Editorial Team added an answer I used the solution explained in my comment above: Yes… May 16, 2026 at 10:56 am
  • Editorial Team
    Editorial Team added an answer Store selected index in your controller. Return cell's height depending… May 16, 2026 at 10:56 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I'm trying to write a linq-to-sql query using || that behaves the same way
I'm trying to write Linq-To-SQL queries in LinqPad to help migrate users from old
I'm trying to write some LINQ To SQL code that would generate SQL like
I'm trying to write a linq to sql method that handles sorting, paging, and
I'm trying to write a query in Oracle SQL to access a particular substring
LINQ gurus, I am looking for help to write a query... I have a
Following this other question on how to make parametrized sql query on classic asp
What is the correct way to write this JPA query? I am just guessing
So my situation is that I have a linq-to-sql model that does not allow
I'm trying to return an XML file based on my query results. I'm very

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.