2011-08-05 73 views
0

您好我有一個像這樣的查詢:LINQ到實體例外

var queryGridData = from question in questions 
    select new { 
     i = question.Id, 
     cell = new List<string>() { question.Id.ToString(), question.Note, question.Topic } 
    }; 

轉換的int導致所需要的ToString()部分:

LINQ to Entities does not recognize the method 'System.String.ToString()' method, and this method cannot be translated into a store expression. 

Hmmmmmmmmmmm。我需要它作爲string進入collection。有任何想法嗎?

回答

0

我會親自執行查詢的剛夠在數據庫中,以提供所需的值,並做休息.NET:

var queryGridData = questions.Select(q => new { q.Id, q.Note, q.Topic }) 
          .AsEnumerable() // Do the rest locally 
          .Select(q => new { i = q.Id, 
               cell = new List<string> { 
                q.Id.ToString(), 
                q.Note, 
                q.Topic 
               } }); 

(此格式是可怕的,但希望它」在IDE中有更多的空間:)會更容易做得很好:)

+0

太好了,謝謝你正在做我想做的! :) –