0

I used string.join but not working.

 IQueryable<CandidateVModel> list = cRepository.Table.Where(x=> !x.CFDemand.Any(y => y.AStatusId == (int) TStatus.SWork)).Select(x => new CandidateVModel
        {
            ...
            Email = x.Email,
            Tags = x.Tags,
            Comments= string.Join(", ",x.CFDemand.SelectMany(y=>y.JInterview.SelectMany(z=>z.JInterviewer.SelectMany(t=>t.JInterviewerFeedback.Select(a=>a.Comments))))),
            Ref= x.Ref
        }).AsExpandable().Where(p);

Error:Message = "LINQ to Entities does not recognize the method 'System.String Join(System.String, System.Collections.Generic.IEnumerable`1[System.String])' method, and this method cannot be translated into a store expression."

hakan hakyemez
  • 94
  • 1
  • 2
  • 13
  • 2
    That needs to be seriously re-thought.... I got lost after the first select many let alone the next 3. This is a code smell to me... – Callum Linington Dec 17 '15 at 16:54
  • There's no SQL equivalent to `String.Join`so EF cannot translate that to SQL. If you can provide more detail as to your data model you may get some help pulling both sets and joining them in Linq-to-Objects. – D Stanley Dec 17 '15 at 16:57
  • refer below link:- http://stackoverflow.com/questions/4095658/how-do-i-concatenate-strings-in-entity-framework-query – Sahi Dec 18 '15 at 11:22

1 Answers1

0

Without digging too much into this, one way to resolve LINQ to Entities does not recognize the method issues is to simplify what you're getting from the database, and create a helper property on your viewmodel like so:

    [IgnoreDataMember]
    public IEnumerable<string> CommentsFromDb
    {
        set
        {
            Comments = string.Join(", ", value);
        }
    }

[IgnoreDataMember] will keep this helper property from getting serialized.

And update your code snippit to be this:

...
CommentsFromDb = x.CFDemand.SelectMany(y=>y.JInterview.SelectMany(z=>z.JInterviewer.SelectMany(t=>t.JInterviewerFeedback.Select(a=>a.Comments))))
John
  • 17,163
  • 16
  • 65
  • 83