SSC
SSC

Reputation: 311

Select 2 tables using LINQ

I have a query like this :

var q2 = from i in dbconnect.tblComplementContracts
                 join b in dbconnect.tblContracts on i.contractId equals  b.contractId
                where (i.complementDate.Value - GetTime()).TotalDays <= _permission
                select i;

I want to access both of "i" and "b" fields,For example i tried "select i,b" but it didn't work what should i do ?

Thanks

Upvotes: 0

Views: 72

Answers (1)

Tim Schmelter
Tim Schmelter

Reputation: 460278

You can use an anonymous type:

var q2 = from i in dbconnect.tblComplementContracts
         join b in dbconnect.tblContracts on i.contractId equals  b.contractId
         where (i.complementDate.Value - GetTime()).TotalDays <= _permission
         select new { I = i, B = b};

foreach (var x in query)
{
    Console.WriteLine("complementDate:{0} contractId:{1}", 
        x.I.complementDate, x.B.contractId);
}

Upvotes: 4

Related Questions