forum

Home / DeveloperSection / Forums / How to get SecondOrDefault?

How to get SecondOrDefault?

Anonymous User 3210 19-Aug-2014

I have a simple linq lambda statement

Interactions = new BindableCollection<InteractionDTO>(ctx.Interactions.Where(x =>
x.ActivityDate > DateTime.Today)
   .Select(x => new InteractionDTO
   {
       Id = x.Id,
       ActivityDate = x.ActivityDate,
       subject = x.Subject,
       ClientNames = x.Attendees.Count == 1 ? x.Attendees.FirstOrDefault().Person.CorrespondenceName :
       x.Attendees.FirstOrDefault().Person.CorrespondenceName : "Multiple attendees"
    }));
This will give me the first Client Name, I'm trying to have it appear First 2 attendees followed by dots. I tried this
ClientNames = x.Attendees.Count == 1 ?
             x.Attendees.FirstOrDefault().Person.CorrespondenceName :
             x.Attendees.FirstOrDefault().Person.CorrespondenceName +
             x.Attendees.Skip(1).FirstOrDefault().Person.CorrespondenceName + " ..."

But I get this error:

The method 'Skip' is only supported for sorted input in LINQ to Entities. The method 'OrderBy' must be called before the method 'Skip'.


c# c# 
Updated on 19-Aug-2014
I am a content writter !

Can you answer this question?


Answer

1 Answers

Liked By