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."

3
  • 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... Commented Dec 17, 2015 at 16:54
  • There's no SQL equivalent to String.Joinso 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. Commented Dec 17, 2015 at 16:57
  • refer below link:- stackoverflow.com/questions/4095658/… Commented Dec 18, 2015 at 11:22

1 Answer 1

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))))
Sign up to request clarification or add additional context in comments.

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.