Include() is not working as LEFT JOIN (Entity Framework 6)

c# ef-code-first entity-framework-6 left-join

Question

I appreciate your assistance in advance. I have a question concerning something that happened to me while using theinclude() the Instance Model 6 technique. As far as I can tell, the include method functions asLEFT JOIN when the contained item isNULL and asOUTER JOIN when the item matches.

I'll give you the example that just came to me so you can clarify for me what happened.

To my tables, I have the following models:

public class Booking
    {
        [Key]
        public int ID{ get; set; }

        public string Description{ get; set; }

        public decimal Amount{ get; set; }

        public decimal AmoutPaid{ get; set; }

        public DateTime? Checkin { get; set; }

        public DateTime? Checkout { get; set; }

        [ForeignKey("SourceBooking ")]
        public int SourceBookingId { get; set; }

        public SourceBooking SourceBooking { get; set; }
    }





public class SourceBooking
{
    [Key]
    public int ID{ get; set; }

    public string Name{ get; set; }

    public decimal CommissionFee{ get; set; }
}

The is theDbContext :

 public class BookingContext:DbContext
{
    public BookingContext():base("bookingConnection")
    {
    }

    public DbSet<Booking> Bookings{ get; set; }

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {

        modelBuilder.Entity<SourceBooking>().ToTable("sourcebookings", "public");

        modelBuilder.Entity<Booking>().ToTable("bookings", "public");

    }
}

Using the following piece of code has resulted in the following unclear situation:

var db = new BookingContext ();

var bookings = db.Bookings.Include (b => b.SourceBooking);

I tended since the records did not come whose in the results.SourceBooking is NULL This would mean aLEFT JOIN made would be.

Could someone please explain this to me and provide a potential solution?

Thanks.

1
1
10/4/2017 11:10:08 AM

Accepted Answer

ZZZ_tmp
8
10/4/2017 11:26:31 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow