Take this sample:
public class RentContext : DbContext { public DbSet<Student> Students { get; set; } public DbSet<Rent> Rents { get; set; } public DbSet<Car> Cars { get; set; } } public class Car { public int Id { get; set; } public string Model { get; set; } public double Price { get; set; } } public class Rent { public int Id { get; set; } public Student Student { get; set; } public Car Car { get; set; } } public class Student { public int Id { get; set; } public string Name { get; set; } public int Year { get; set; } }
The rent includes Student and Car.
Let's make a request with unique Include clauses:
var rents = ctx.Rents .Include(x => x.Student) .Include(x => x.Car)
This is the generated sql:
SELECT [Extent1].[Id] AS [Id], [Extent2].[Id] AS [Id1], [Extent2].[Name] AS [Name], [Extent2].[Year] AS [Year], [Extent3].[Id] AS [Id2], [Extent3].[Model] AS [Model], [Extent3].[Price] AS [Price] FROM [dbo].[Rents] AS [Extent1] LEFT OUTER JOIN [dbo].[Students] AS [Extent2] ON [Extent1].[Student_Id] = [Extent2].[Id] LEFT OUTER JOIN [dbo].[Cars] AS [Extent3] ON [Extent1].[Car_Id] = [Extent3].[Id]
Make a duplicate query Include:
var rents = ctx.Rents .Include(x => x.Student) .Include(x => x.Car) .Include(x => x.Student) .ToList();
You will get this sql:
SELECT [Extent1].[Id] AS [Id], [Extent2].[Id] AS [Id1], [Extent2].[Name] AS [Name], [Extent2].[Year] AS [Year], [Extent3].[Id] AS [Id2], [Extent3].[Model] AS [Model], [Extent3].[Price] AS [Price] FROM [dbo].[Rents] AS [Extent1] LEFT OUTER JOIN [dbo].[Students] AS [Extent2] ON [Extent1].[Student_Id] = [Extent2].[Id] LEFT OUTER JOIN [dbo].[Cars] AS [Extent3] ON [Extent1].[Car_Id] = [Extent3].[Id]
As you can see, EF is smart enough to create the same sql even if you specify Include more than once.
UPDATE: Re-enable (many times)
Let's try this:
var rents = ctx.Rents .Include(x => x.Student) .Include(x => x.Car) .Include(x => x.Car) .Include(x => x.Car) .Include(x => x.Car) .Include(x => x.Car) .Include(x => x.Car) .Include(x => x.Car) .Include(x => x.Car) .Include(x => x.Car) .Include(x => x.Car) .Include(x => x.Car) .Include(x => x.Car) .Include(x => x.Car) .Include(x => x.Car) .Include(x => x.Car) .Include(x => x.Car) .Include(x => x.Car) .Include(x => x.Car) .Include(x => x.Car) .Include(x => x.Car) .Include(x => x.Car) .Include(x => x.Car) .Include(x => x.Car) .Include(x => x.Car) .Include(x => x.Student) .Include(x => x.Student) .Include(x => x.Student) .Include(x => x.Student) .Include(x => x.Student) .Include(x => x.Student) .Include(x => x.Student) .Include(x => x.Student) .Include(x => x.Student) .Include(x => x.Student) .Include(x => x.Student) .Include(x => x.Student) .Include(x => x.Student) .ToList();
Repeats Includes several times. And here is the generated sql:
SELECT [Extent1].[Id] AS [Id], [Extent2].[Id] AS [Id1], [Extent2].[Name] AS [Name], [Extent2].[Year] AS [Year], [Extent3].[Id] AS [Id2], [Extent3].[Model] AS [Model], [Extent3].[Price] AS [Price] FROM [dbo].[Rents] AS [Extent1] LEFT OUTER JOIN [dbo].[Students] AS [Extent2] ON [Extent1].[Student_Id] = [Extent2].[Id] LEFT OUTER JOIN [dbo].[Cars] AS [Extent3] ON [Extent1].[Car_Id] = [Extent3].[Id]
Only the same code again. So yes. We could say that everything will be fine, although a little strange.
Hope this helps!