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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T23:11:01+00:00 2026-05-21T23:11:01+00:00

I want to know if the Linq and SQL are equal ( means Linq

  • 0

I want to know if the Linq and SQL are equal ( means Linq will return same set of results as the SQL ? I dont have data in tables and I need to convert SQL to LINQ. Please suggest

 var excludeTypes = new[]
               {
                  "CA00", "CA01", "CA03", "CA04", "CA02",
                  "PA00", "PA01", "PA02", "PA03", "PA04"     
               };

 var accounts =
                from account in context.Accounts
                from owner in context.AccountOwners
                from business in context.Businesses
                from accountStatus in context.AccountStatuses
                from legalStatus in context.LegalStatuses
                where !excludeTypes.Contains(account.AccountType)
                select new AccountsReport { Account = account };


 ALTER VIEW [dbo].[vwRptBorrowerAccount]  
AS  
SELECT dbo.tblAccount.[Creditor Registry ID], dbo.tblAccount.[Account No], dbo.tblAccount.[Date Opened], dbo.tblAccount.[Account Status ID],   
               dbo.tblAccount.[Date First Reported], dbo.tblAccount.[Credit Limit], dbo.tblAccount.Balance, dbo.tblAccount.[Minimum Installment], dbo.tblAccount.[Account Type],   
               dbo.tblAccount.Term, dbo.tblAccount.Purpose, dbo.tblAccount.[Account Owner Notes], dbo.tblAccount.[Creditor Notes], dbo.tblAccount.Collateral,   
               dbo.tblAccount.[Collateral Value], dbo.tblAccount.[Legal Status ID], dbo.tblAccount.[Legal Status Date], dbo.tblAccount.LastUpdatedBy,   
               dbo.tblAccount.LastUpdated, dbo.tblAccount.[Unique ID], dbo.tblAccount.[Account Status Date], dbo.tblAccount.Payment, dbo.tblAccount.[Payment Date],   
               dbo.tblAccount.[Balance Date], dbo.tblAccount.[Term Frequency], dbo.tblAccount.[State Change Date],   
               dbo.fn_GetAccountTypeDescription(dbo.tblAccount.[Account Type]) AS [Account Type Description], dbo.tblBusiness.[Business Name] AS CreditorName,   
               dbo.tblBusiness.Address AS CreditorAddress, dbo.tblBusiness.City AS CreditorCity, dbo.tblBusiness.State AS CreditorState,   
               dbo.tblLegalStatus.[Legal Status Description] AS [Legal Status], dbo.tblAccountStatus.[Account Status Description] AS [Account Status],   
               dbo.tblAccountOwner.[Account Owner Registry ID]  
FROM  dbo.tblAccount INNER JOIN  
               dbo.tblAccountOwner ON dbo.tblAccount.[Creditor Registry ID] = dbo.tblAccountOwner.[Creditor Registry ID] AND   
               dbo.tblAccount.[Account No] = dbo.tblAccountOwner.[Account No] INNER JOIN  
               dbo.tblBusiness ON dbo.tblAccount.[Creditor Registry ID] = dbo.tblBusiness.[Registry ID] INNER JOIN  
               dbo.tblAccountStatus ON dbo.tblAccount.[Account Status ID] = dbo.tblAccountStatus.[Account Status ID] INNER JOIN  
               dbo.tblLegalStatus ON dbo.tblAccount.[Legal Status ID] = dbo.tblLegalStatus.[Legal Status ID]  
WHERE (dbo.tblAccount.[Account Type] NOT IN ('CA00', 'CA01', 'CA03', 'CA04', 'CA02', 'PA00', 'PA01', 'PA02', 'PA03', 'PA04'))  
  • 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-21T23:11:02+00:00Added an answer on May 21, 2026 at 11:11 pm

    No, your linq is not equivalent to your sql. You are missing the relationships between the tables.


    The second and third “from” is translated into a call to System.Linq.Queryable.SelectMany. Since there is no relationship specified, this query matches every Account to every AccountOwner and then each result pair is matched to every Business. This is known as cartesian join (all possible matchings).

    from account in context.Accounts
    from owner in context.AccountOwners
    from business in context.Businesses
    

    A more traditional approach, is to specify the relationship in the query. This query matches every Account to its AccountOwner and then every Account is matched to its Business. This is known as inner join. (Note, must use keyword equals. Also note strict scoping rules on (leftside) equals (rightside)).

    from account in context.Accounts
    join owner in context.AccountOwners
      on new {account.RegistryId, account.AccountNo}
      equals new {owner.RegistryId, owner.AccountNo}
    join business in context.Businesses
      on account.CreditorRegistryID
      equals business.RegistryID
    

    The second and third “from” is translated into a call to System.Linq.Queryable.SelectMany. Since there is a relationship specified, this query matches every Account to its AccountOwners and to its Businesses. This is an inner join (Account = 1, others = Many).

    from account in context.Accounts
    from owner in account.AccountOwners
    from business in account.Businesses
    

    This query matches every Account to its only AccountOwner and its only Business.This is also an inner join (Account = Many, others = 1).

    from account in context.Accounts
    let owner = account.AccountOwner
    let business = account.Business
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have an existing ASP.NET solution that uses LINQ-to-SQL to insert data into
I want to insert data into sql table in silverlight application. I know how
I know LINQ doesn't have the SQL IN clause but rather uses contains. Can
I have a LINQ to SQL class called Data with a column of type
just want to know if linq to sql auto updated the id column of
I want to know what a virtual base class is and what it means.
I want to know how does the SQL Server know what @p# is in
I want to replicate this query in LINQ to SQL but am too unfamiliar
I have some linq to sql method and when it does the query it
I'm working with a database and I want to start using LINQ To SQL

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.