I am using LINQ with an Entity base to join three tables, and I am returning an IList interface.
I want to apply a foreach for this return value so that I can populate the values ββin my model.
This is how I join:
public IList GetData(long Id) { //var q = dataContext.tblUsers.AsEnumerable().Join(dataContext.tblUsersProfiles.AsEnumerable(),) var query = from u in dataContext.tblUsers join p in dataContext.tblUsersProfiles on u.ProfileId equals p.Id join c in dataContext.tblComments on u.Id equals c.Commentedby where c.Id == Id select new { u.Firstname, u.Lastname, p.ProfilePicPath, c.Comment, c.CommentDate }; return query.ToList(); }
I want to fill in these values ββin my list of models. I tried this:
var lst = repository.GetDate(Id); foreach (var item in lst) { }
But I can not access the Firstname / Lastname , etc.
I also tried using item and object[] item objects, but both of them also do not work.
How can I apply for each on IList`?
This will work fine. If in this case I can return a DataTable instead of an IList .
source share