2
這個特定的查詢是給我一個錯誤,請告訴我該怎麼錯在何處查詢問題:無法強制轉換對象
public IList <BC_FeedbackBy> GetFeedbackList()
{
int feedbackId = 0;
string feedbackName = string.Empty;
using (brandconnectionsEntities modelObject = new brandconnectionsEntities())
{
return (IList<BC_FeedbackBy>)(from s in modelObject.BC_FeedbackBy
select new
{
feedbackId =s.FeedbackById ,
feedbackName=s.FeedbackBy ,
})
.ToList();
}
}
誤差
Unable to cast object of type 'System.Collections.Generic.List
`1[<>f__AnonymousType0`2[System .Int32,System.String]]' to type
'System.Collections.Generic.IList`1[BrandConnectionsPrototype.Models.BC_FeedbackBy]'.
你並不需要一個構造函數,缺省產生的空單的工作,因爲你正在使用對象初始化:http://msdn.microsoft.com/en-us/圖書館/ bb384062.aspx – 2010-02-01 12:56:02
Doh,你說得對。我正在考慮使用構造函數,但因爲我剛剛從問題中複製代碼,所以我最終使用了屬性,所以默認的構造函數就足夠了。謝謝! – 2010-02-01 13:25:56