---
title: "How to join Multiple tables using Repository Pattern & Entity Framework?"  
description: "How to join Multiple tables using Repository Pattern & Entity Framework?"  
author: "Anonymous User"  
published: 2013-12-17  
updated: 2013-12-17  
canonical: https://www.mindstick.com/forum/1785/how-to-join-multiple-tables-using-repository-pattern-entity-framework  
category: "c#"  
tags: ["c#"]  
reading_time: 2 minutes  

---

# How to join Multiple tables using Repository Pattern & Entity Framework?

I need to join [multiple tables](https://www.mindstick.com/forum/159848/how-to-get-multiple-tables-using-entity-framework-core) using [repository pattern](https://www.mindstick.com/articles/13071/generic-repository-pattern-with-unit-of-work-uow) & [Entity Framework](https://www.mindstick.com/articles/1566/crud-operations-using-entity-framework-code-first-approach) (using C#). Is this possible?

If so, please let me know how to do the same.

Thanks in [advance](https://www.mindstick.com/blog/33258/jee-mains-and-jee-advance-exams)!

## Replies

### Reply by Pravesh Singh

Hi Ashish,

\
In EF, joining [tables](https://www.mindstick.com/articles/336597/introduction-of-html-tables-for-web-development) is done through the use of Navigation Properties. Basically, EF does it for you. When implementing in your Repositories, may it be Generic or not, you can call the Include method when building your query expression to tell EF to populate the navigation properties for you.

\

```
public class Dog{    public int DogId { get; set; }    public string Name { get; set; }    public int OwnerId { get; set;}    public Owner Owner { get; set; } // the navigation property}public class Owner{    public int OwnerId { get; set; }    public string Name { get; set; }    // another navigation property    // all the dogs that are related or owned by this specific owner    public ICollection<Dog> DogList { get; set; }    public ICollection<Cat> CatList { get; set; }}
```

## \

## Here's a sample code snippet using Include:

## \

```
public virtual IEnumerable<Dog> Retrieve(){    var _query = context.Dog.Include(a => a.Owner);    ...    ...// rest of your code}
```

\

And for [multiple](https://www.mindstick.com/blog/12797/iowa-is-expected-to-see-heavy-growth-in-multiple-sectors) tables you can nest the include method like so:

\

\

```
public virtual IEnumerable<Owner> Retrieve(){    // you can nest as many as you want if there are more nav properties    var _query = context.Owner        .Include(a => a.DogList)        .Include(a => a.CatList);    ...    ...// rest of your code}
```

Once you include nav properties then that is basically joining those other tables. Just look at the SQL being generated by the query. Hope this helps!


---

Original Source: https://www.mindstick.com/forum/1785/how-to-join-multiple-tables-using-repository-pattern-entity-framework

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
