0

my code is

    var model = dt.FishEventScheduleVaccination
            .Join(
                dt.FishEventSchedule,
                vaccination => vaccination.ScheduleId,
                schedule => schedule.ScheduleId,
                (vaccination, schedule) => new { vaccination, schedule }
            )
            .Select(q=>new {
                q.vaccination,
                q.schedule
            })
            .Where(w=>w.schedule.Start>DateTime.Now).ToList();
        var rtn=new List<FishEventScheduleVaccination>();
        foreach (var m in model) {
            var item = m.vaccination;
            item.FishEventSchedule = m.schedule;
            rtn.Add(item);
        }

i want do with only lambda query, not foreach. how can i do? Is it possible?

2
  • 1
    You can use the .ForEach(x => {...}) method, but this results in a loop, too. If you need a loop. you need a loop. Commented Nov 10, 2015 at 9:19
  • 1
    Since you are mutating the items, this is no more a query, hence do it with a loop or whatever is appropriate. Commented Nov 10, 2015 at 9:29

2 Answers 2

1

Try this instead:

dt.FishEventScheduleVaccination
    .Join(dt.FishEventSchedule,
          vaccination => vaccination.ScheduleId,
          schedule => schedule.ScheduleId,
          (vaccination, schedule) => new { vaccination, schedule })
    .Where(w => w.schedule.Start > DateTime.Now)
    .AsEnumerable()
    .Select(q => { q.vaccination.FishEventSchedule = q.schedule; return q.vaccination; })
    .ToList();
Sign up to request clarification or add additional context in comments.

Comments

1
from r in Entities.tbl join q in Entities.tbl on r.Id equals q.Id2 select new
{
    Id = r.Column + " " + r.Column, Data = q.Column + " " + q.Column 
};

I think this should solve your Query

OR

you can also try something like this:

db.DTOPageSets.Join(db.DTOPageSets
                    .AsEnumerable(), a => a.ContentPageID, b => b.CategoryID, (a, b) => a);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.