Itgirl16
asked on
LINQ JOIN and foreach loop
Actually I am trying to join table using LINQ query and than doing select thing and trying to foreach loop of the whole thing and trying to compare that thing but It is giving me error .
DataClassesDataContext db = new DataClassesDataContext();
var activities = from o in db.maintenanceOrders
from r in db.rentalUnits
from tr in db.tenantRentals
where tr.TenantID == Convert.ToInt32(TenantID)
&& o.RentalUnitID == tr.rentalUnitID
&& o.Scheduled_Date.Date == e.Day.Date
select new { o,tr};(How to select two things in LINQ and how to loop though of two things in foreach loop how can I mention that.
foreach (maintenanceOrders o in activities)
{
HyperLink link = new HyperLink();
link.Text = o.Comments;
link.CssClass = "activity";
//link.NavigateUrl =
// Page.ClientScript.GetPostB ackClientH yperlink(C alendarLin kButton1,
// a.ActivityID.ToString(), false);
e.Cell.Controls.Add(link);
}
DataClassesDataContext db = new DataClassesDataContext();
var activities = from o in db.maintenanceOrders
from r in db.rentalUnits
from tr in db.tenantRentals
where tr.TenantID == Convert.ToInt32(TenantID)
&& o.RentalUnitID == tr.rentalUnitID
&& o.Scheduled_Date.Date == e.Day.Date
select new { o,tr};(How to select two things in LINQ and how to loop though of two things in foreach loop how can I mention that.
foreach (maintenanceOrders o in activities)
{
HyperLink link = new HyperLink();
link.Text = o.Comments;
link.CssClass = "activity";
//link.NavigateUrl =
// Page.ClientScript.GetPostB
// a.ActivityID.ToString(), false);
e.Cell.Controls.Add(link);
}
Hello Itgirl16
Try the attached code sample. I guessed at the 2nd join as I wasn't sure how the variable 'r' was being used... So feel free to correct that :)
Thanks,
Richard
Try the attached code sample. I guessed at the 2nd join as I wasn't sure how the variable 'r' was being used... So feel free to correct that :)
Thanks,
Richard
DataClassesDataContext db = new DataClassesDataContext();
var activities = from o in db.maintenanceOrders
join e in db.rentalUnits
on e.Day.Date equals o.Scheduled_Date.Date // I guessed at this line as I wasn't sure what 'r' was///
join tr in db.tenantRentals
on tr.rentalUnitID equals o.RentalUnitID
where tr.TenantID == Convert.ToInt32(TenantID)
select new { o, tr };
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
@yogsoft: thanks it works..............Thanks for your help.........
Your Linq query.ToList() will give the result in list. Then apply foreach on that.
http://bytes.com/topic/c-sharp/answers/792588-linq-tolist-when-querying-multiple-sources