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

  • Home
  • SEARCH
  • 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 474k
  • Answers 474k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

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

    • 7 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer i haven't test it but i guess that you can… May 16, 2026 at 4:21 am
  • Editorial Team
    Editorial Team added an answer Not seeing your actual custom event class makes it a… May 16, 2026 at 4:21 am
  • Editorial Team
    Editorial Team added an answer The best advice I can give from a learning perspective… May 16, 2026 at 4:21 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

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.