DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Related

  • From Naked Objects to Naked Functions
  • Hyperlambda, the Fastest Programming Language in the World
  • Working With Transactions in Entity Framework Core and Entity Developer
  • Working With Lazy Loading and Eager Loading in Entity Framework Core and Entity Developer

Trending

  • Automating Data Pipelines: Generating PySpark and SQL Jobs With LLMs in Cloudera
  • Detection and Mitigation of Lateral Movement in Cloud Networks
  • Beyond Code Coverage: A Risk-Driven Revolution in Software Testing With Machine Learning
  • How to Ensure Cross-Time Zone Data Integrity and Consistency in Global Data Pipelines
  1. DZone
  2. Data Engineering
  3. Databases
  4. Include With Where Clause

Include With Where Clause

In this article, take a look at a tutorial that explains how to write a certain query in Entity Framework.

By 
Muhammad Adil Malik user avatar
Muhammad Adil Malik
·
Feb. 18, 20 · Tutorial
Likes (3)
Comment
Save
Tweet
Share
24.4K Views

Join the DZone community and get the full member experience.

Join For Free

Ever thought about writing the following query in Entity Framework?

SQL
 




xxxxxxxxxx
1


 
1
Select * From Employees e
2
left join Employees_Attendance ea on e.id=ea.employee_id and ea.date between {{startdate}} and {{enddate}}



In the above query, {{startdate}} and {{enddate}} are the parameters. This query will list all of the employees, but only the attendance that are between startdate and enddate. 

While working on a project, it seems very hard to do this using the standard EF Core library, so I found an online solution available I thought worth sharing.

A library has a lot of useful functionalities, including the one we are trying to solve, that can be downloaded from https://entityframework-plus.net/download.

While using that library's extension method IncludeFilter, the above query can be written in EF Core as follows:

C#
 




xxxxxxxxxx
1


 
1
_dbContext.Employees
2
    .IncludeFilter(x => x.EmployeeAttendance.Where(y => y.Date >= {{StartDate}} && y.Date <= {{EndDate}}))



StartDate and EndDate are the parameters that can be replaced by the parameter in your solutions.

Thanks for reading. Happy coding!

Further Reading

Consider Using [NOT] EXISTS Instead of [NOT] IN

Entity Framework Database

Opinions expressed by DZone contributors are their own.

Related

  • From Naked Objects to Naked Functions
  • Hyperlambda, the Fastest Programming Language in the World
  • Working With Transactions in Entity Framework Core and Entity Developer
  • Working With Lazy Loading and Eager Loading in Entity Framework Core and Entity Developer

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!