这个特殊的查询给我一个错误,请告诉我哪里出错了
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]'.
答案 0 :(得分:3)
select new
创建新匿名类型的实例。查询会创建这些列表,然后尝试将其强制转换为IList<BC_FeedbackBy>
。而是在查询中创建BC_FeedbackBy
的新实例。
像
这样的东西select new BC_FeedbackBy()
{
feedbackId =s.FeedbackById ,
feedbackName=s.FeedbackBy ,
})