LINQ - problem? - Asked By shah zeb on 31-May-11 02:41 AM

Hi
Can we apply a join on tables of different data context

Regards,
sz
Jitendra Faye replied to shah zeb on 31-May-11 02:44 AM
Follow this sample code from loin different data context.

   class Program
{
    static AccountContextDataContext aContext = new AccountContextDataContext(@"Data Source=;Initial Catalog=;Integrated Security=True");
    static LoanContextDataContext lContext = new LoanContextDataContext(@"Data Source=;Initial Catalog=;Integrated Security=True");
    static void Main()
    {
        var query = from a in aContext.ACCOUNTs
                    join app in aContext.APPLICATIONs on a.GUID_ACCOUNT_ID equals app.GUID_ACCOUNT
                    where app.GUID_APPLICATION.ToString() == "24551D72-D4C2-428B-84BA-5837A25D8CF6"
                    select GetLoans(app.GUID_APPLICATION);
        IEnumerable<LOAN> loan = query.First();
        foreach (LOAN enumerable in loan)
        {
            Console.WriteLine(enumerable.GUID_LOAN);
        }
        Console.ReadLine();
    }
    private static IEnumerable<LOAN> GetLoans(Guid applicationGuid)
    {
        return (from l in lContext.LOANs where l.GUID_APPLICATION == applicationGuid select l).AsQueryable();
    }
}
hope this will help you.

Riley K replied to shah zeb on 31-May-11 02:51 AM
Yes you can

var query = (from a in dc1.TableA join b in dc2.TableB on a.id equals b.id select new { a, b }).ToList()

Use the above way