SubSonic 3 Linq projecting anonymous types but not class types

て烟熏妆下的殇ゞ 提交于 2019-12-01 01:54:58

There is no real answer to this. I have encountered this more often then not. keeping the order of assignment same as the order of reading help. ie. in Debug time if you see the QueryText and see in what order the columns are read from db. and then keep the assignment same as the order of sql Select Statement in QueryText. Resolves the problem 9 out of 10 times.

Try this instead:

IList<FruitView> fruits = (
         from f in db.Fruits
             select new FruitView {
                 MyFruitID = f.FruitID,
                 MyFruitName = f.FruitName
             }).ToList();

or

IQueryable<FruitView> fruits = 
         from f in db.Fruits
             select new FruitView {
                 MyFruitID = f.FruitID,
                 MyFruitName = f.FruitName
             };

..and foreach as before.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!