'Using join method on Entity Framework cause trouble

I got this error

An unhandled exception of type 'System.StackOverflowException' occurred in EntityFramework.dll

when I use join for listing data from the database by string array.

This is my code:

public List<tbl_Customer> Getcustomers(string [] Vouchers) // Vouchers length 1700
{
    try
    {
        using (TurkusDEntities _db = new TurkusDEntities())
        {
            return _db.tbl_Customer
                      .Where(c => c.fldStatus != 0)
                      .Join(Vouchers, c => c.fldVoucher, k => k, (c,k ) => c)
                      .ToList();
        }
    }
    catch (Exception)
    {
        throw;
    }
} 

tbl_Customer has more than 50,000 rows. If I do not use join method, working without any error. With join method, the code should return around 5,000 rows.



Solution 1:[1]

After long research, I found the following solution. I was getting an error when I wanted to use join with the string [] Vouchers i created under certain conditions.Instead of string [] Vouchers i used join without create any variable or model like the following codes.

model.Customers = _db.tbl_Customer.Where(c => c.fldStatus != 0)
///start
                    .Join(_db.tbl_Reservation
                    .Where(c => c.fldTourDateTime >= start && c.fldTourDateTime <= finish && c.fldStatus != 0)
                    .Join(_db.tbl_ResAccount.Where(k => k.fldStatus != 0), z => z.fldReservation, y => y.fldReservationNumber, (z, y) => z)
                    .Select(c=>c.fldVoucher)
/// finish  
                    ,c => c.fldVoucher, k => k, (c, k) => c)
                    .ToList();

I was creating string [] Vouchers with conditions between start and finish.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 cancan