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 1034893
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T14:27:47+00:00 2026-05-16T14:27:47+00:00

Please help me write LINQ for this SQL select svc.SvcName, svcOptions.SvcOptionName, svcMap.Price from svcMap

  • 0

Please help me write LINQ for this SQL

select svc.SvcName, svcOptions.SvcOptionName, svcMap.Price from svcMap
inner join 
svc
on svcMap.SvcId = svc.SvcId
inner join 
svcOptions
 on svcOptions.SvcOptionId = CASE WHEN (svcMap.DesiredSvcOptionId <> 0 AND svcMap.DesiredSvcOptionId <> svc.DisabledSvcOptionId) THEN
                                                                        svcMap.DesiredSvcOptionId
                                                                WHEN (svcMap.PresentSvcOptionId <> svc.DisabledSvcOptionId) THEN
                                                                    svcMap.PresentSvcOptionId
                                                                ELSE
                                                                    0
                                                                END
where svcMap.ToBill = 1
and
(
  (svcMap.DesiredSvcOptionId = 0 AND svcMap.PresentSvcOptionId <> svc.DisabledSvcOptionId)
  OR 
  (svcMap.DesiredSvcOptionId <> 0 AND svcMap.DesiredSvcOptionId <> svc.DisabledSvcOptionId)
)

SOLUTION

This is the solution that I implemented and it gave me exactly what I needed when I cross checked it with LinqPad

from svcMap in db.ServicesMap
  join svc in db.Services on svcMap.SvcId equals svc.SvcId
  join option in db.Options on
    ((svcMap.DesiredSvcOptionId != 0 && svcMap.DesiredSvcOptionId != svc.DisabledSvcOptionId)
       ? svcMap.DesiredSvcOptionId
       : (svcMap.PresentSvcOptionId != svc.DisabledSvcOptionId)
           ? svcMap.PresentSvcOptionId
           : 0)
    equals option.SvcOptionId
where svcMap.ToBill == 1
      && (
           (svcMap.DesiredSvcOptionId == 0 &&
            svcMap.PresentSvcOptionId != svc.DisabledSvcOptionId)
           ||
           (svcMap.DesiredSvcOptionId != 0 &&
            svcMap.DesiredSvcOptionId != svc.DisabledSvcOptionId)
         )
select
  new 
    {
      svc.SvcName,
      option.SvcOptionName,
      svcMap.Price.GetValueOrDefault()
    }
  • 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-16T14:27:47+00:00Added an answer on May 16, 2026 at 2:27 pm

    Why have a CASE in your joining criteria? What do you expect the optimizer to do with that exactly?

    Here’s a literal translation.

    from svcMap in db.svcMaps
    where svcMap.ToBill == 1
    let svc = svcMap.Svc
    where (svcMap.Desired == 0 && svcMap.Present <> svc.Disabled)
      || (svcMap.Desired <> 0 && svcMap.Desired <> svc.Disabled)
    let optionId =
      svcMap.Desired <> 0 && svcMap.Desired <> svc.Disabled ? svcMap.Desired :
      svcMap.Present <> svc.Disabled ? svc.Present :
      0
    from option in db.Options
    where option.SvcOptionId == optionId
    select new {svc.SvcName, option.SvcOptionName, svcMap.Price }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

SELECT * FROM CUSTOMERS WHERE RTRIM(ISNULL([SHORTNAME],'')) LIKE '%john%' I want to write this using
java experts can you please help me write detached queries as a part of
Please help me to write a trigger that adds new rows to a table.
Please help to replace these jQuery functions with Prototype ones: $(button,input,label,select,textarea).bind('mouseover mouseout', function(){$(this).toggleClass('hover')}); $(button,input,select,textarea).bind('focus
Please help me out with this. I have this small application to load txt
Someone please help me understand why this binding does not work... I have a
please help me solve this issue. I have a client using WCF. I don't
When Executing the following linq to sql statement: var stuff = from l in
I cannot understand how this is possible. Please help!! I have an app with
I am new to SQL server, please can any body help me out how

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.