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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T12:30:47+00:00 2026-05-29T12:30:47+00:00

We are in the process of converting SQL / Stored Procedures to LINQ to

  • 0

We are in the process of converting SQL / Stored Procedures to LINQ to Entities statements.

Currently I am converting this SQL:

declare @startDate DateTime
set @startDate = DATEADD(DD, -30, GETDATE())

select h.*
from  History h (nolock) 
  inner join Quote q (nolock) on h.QuoteID = q.QuoteID 
  inner join Agency (nolock) a on q.AgencyID = a.AgencyID
  inner join DC_PLT_EntityRoles er (nolock) on a.AgencyID = er.EntityID
  inner join DC_PLT_Roles (nolock) r on er.RoleID = r.RoleID
where
  q.Status = 'Inforce' 
  and q.LOB = 'Vacant'  
  and q.EffectiveDate > @startDate 
  and h.Deleted is null 
  and h.DeprecatedBy is null 
  and h.TransactionStatus = 'Committed'
  and r.Name = 'Wholesaler'

This is the LINQ to Entities which I wrote up:

var startDate = DateTime.Today.AddDays(-30);    
var results = (from h in Histories
       .Include("Quote")
       .Include("Quote.Agency")
       .Include("Quote.Agency.DC_PLT_Roles")
   where h.Quote.Status == "Inforce" &&  
              h.Quote.LOB == "Vacant" &&        
              h.Quote.EffectiveDate > startDate &&
              h.Deleted == null &&
              h.DeprecatedBy == null &&
              h.TransactionStatus == "Committed" && 
              h.Quote.Agency.DC_PLT_Roles.All(r => r.Name == "Wholesaler")
   select h).ToList();

The problem is the SQL returns 77 rows and my LINQ returns none.

Anyone have any ideas on how I can convert this correctly? Or what I am missing.

Thanks for your help.

R

  • 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-29T12:30:48+00:00Added an answer on May 29, 2026 at 12:30 pm

    h.Quote.Agency.DC_PLT_Roles.All(r => r.Name == "Wholesaler")

    I think this line is your problem. I’m pretty sure you want to use Any here not All. In this instance All means all DC_PLT_Roles for the Agency must have Name == "Wholesaler". Any means there must be one DC_PLT_Role for the agency with Name == "Wholesaler".

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

Sidebar

Related Questions

I am in a process of converting some legacy SQL Server Stored Procedures to
I'm working on converting a stored procedure from SQL server to Oracle. This stored
I am in the process of converting an Access database to SQL Server 2005.
I'm in the process of converting a class hierarchy to be stored in an
I am in process of converting Visual Basic app into Python Django. Currently, it
I'm currently in the process of converting some small personal web sites from WebForms
We're in the process of converting to SQL Server from MySQL . I'm trying
I'm in the process of speeding up Linq to SQL queries in a web
I'm currently in the process of converting over 20k database tables from Corel Paradox
I have a process that runs on a SQL server that is set to

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.