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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T07:35:39+00:00 2026-06-08T07:35:39+00:00

I have an Entity Framework 4 model in my application. I need it to

  • 0

I have an Entity Framework 4 model in my application. I need it to generate the following SQL:

SELECT *
FROM       Reads            AS R
INNER JOIN Images           AS I ON R.ReadId = I.ReadId AND I.ImageTypeId = 2
LEFT OUTER JOIN Alarms      AS A ON R.ReadId = A.ReadId AND A.DomainId IN (103,102,101,2,1,12) AND A.i_active = 1
LEFT OUTER JOIN ListDetails AS L ON L.ListDetailId = A.ListDetailId
WHERE R.i_active = 1

Here’s what I have now for this query in my code:

var items = from read  in query
            join plate in context.Images      on read.ReadId        equals plate.ReadId
            join temp1 in context.Alarms      on read.ReadId        equals temp1.ReadId       into alarms  from alarm in  alarms.DefaultIfEmpty()
            join temp2 in context.ListDetails on alarm.ListDetailId equals temp2.ListDetailId into entries from entry in entries.DefaultIfEmpty()
            where plate.ImageTypeId == 2 && plate.IActive == 1
            select new { read, plate, alarm, entry.OfficerNotes };

How do I modify the Entity Framework query to get the SQL query I need?

  • 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-06-08T07:35:42+00:00Added an answer on June 8, 2026 at 7:35 am

    For Left Joins – I suggest using a from with a where instead of join, I find it makes it cleaner

    For Inner Joins with multiple join conditions – you need to join on two matching anonymous types, or use a from with where conditions

    For x IN list, you need to specify your list outside the query and use the Any method or Contains method

    List<int> domainIds = new List<int>() { 103,102,101,2,1,12 };
    
        var items = from read  in query
                    join plate in context.Images
                    on new { read.ReadId, ImageTypeId = 2 } equals new { plate.ReadId, plate.ImageTypeId }
                    from alarm in context.Alarms
                                         .Where(x => x.IActive == 1)
                                         .Where(x => domainIds.Any(y => y == x.DomainId))
                                         .Where(x => read.ReadId == x.ReadId)
                                         .DefaultIfEmpty()
                    from entry in context.ListDetails 
                                         .Where(x => alarm.ListDetailId == x.ListDetailId)
                                         .DefaultIfEmpty()
                    select new { read, plate, alarm, entry.OfficerNotes };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have an entity framework model with has some inheritance in it. The following
suppose you have an MVC application with the Model represented by an Entity Framework
I have an Entity Framework data model. Part of the model is a Customer
I have created a Dynamic Data site against an Entity Framework Model I have
I have a simple ADO.NET Entity Framework 4.0 model (edmx) which defines database tables
I'm working with a small model in Entity Framework 4.0. I'd like to have
I have the following entities in Entity Framework: public class School { public int
I'm building my application with Entity Framework (model first principle). I'm also using MS
I am new to Entity Framework and i have to start a application within
I have a web application where i need to use entity frame work.Actually i

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.