0

この linq クエリで次のエラーが発生します。

LINQ to Entities はメソッド 'System.Collections.Generic.List 1[System.Char] ToList[Char](System.Collections.Generic.IEnumerable1[System.Char])' メソッドを認識せず、このメソッドはストア式に変換できません。

var result =
(
    from citation in Db.Citation
    where citation.IsActive == true
    select new CitationViewModel
    {
        CitationID = citation.CitationID,
        CitationTitle = citation.CitationTitle,
        DocType = citation.DocType,
        DateOfPub = citation.DateOfPub,
        authors = citation.citation_Authors.Where(c => c.CitationID == citation.CitationID).SelectMany(b => b.Author.AuthorName).ToList(),
    }
);

ここに私のビューモデルがあります:

public class CitationViewModel
{
    public int CitationID { get; set; }
    public string CitationTitle { get; set; }
    public IList<char> authors { get; set; }
}

前もって感謝します。

4

2 に答える 2

0

You can fix the problem if you change the IList<char> authors property in CitationViewModel to

public IEnumerable<string> authors { get; set; }

and then remove the ToList() call in your projection. SelectMany(b => b.Author.AuthorName) returns an IEnumerable<string>.

于 2013-06-08T12:07:01.377 に答える
0

次のようにコードを変更することをお勧めします ( authorsプロパティが現在どのように初期化されているかに注意してください):

var result =
(
    from citation in Db.Citation
    where citation.IsActive == true
    select new CitationViewModel
    {
        CitationID = citation.CitationID,
        CitationTitle = citation.CitationTitle,
        DocType = citation.DocType,
        DateOfPub = citation.DateOfPub,
        authors = new List<char>(citation.citation_Authors.Where(c => c.CitationID == citation.CitationID).SelectMany(b => b.Author.AuthorName)),
    }
);
于 2013-06-07T17:35:39.623 に答える