Sil*_*erX 32 .net c# mysql linq linq-to-entities
我正在使用LINQ语句,从各种表中选择我需要填写一些帖子/帖子后评论样式记录的信息.我得到一个有趣的例外,当我尝试迭代记录集时,该对象必须实现IConvertible.关于它的有趣部分是它似乎只发生在我用来保存数据的匿名类型包含2个以上的泛型集合时.
//select friend timeline posts posts
var pquery = from friend in fquery
join post in db.game_timeline on friend.id equals post.user_id
//join user in db.users on post.friend_id equals user.id into userGroup
//join game in db.games on post.game_id equals game.game_id into gameGroup
select new
{
Friend = friend,
Post = post,
Game = from game in db.games
where game.game_id == post.game_id
select game,
Recipient = from user in db.users
where user.id == post.user_id
select user,
Comments = from comment in db.timeline_comments
where comment.post_id == post.id
join users in db.users on comment.user_id equals users.id
select new { User = users, Comment = comment }
};
Run Code Online (Sandbox Code Playgroud)
(注意:我正在使用MYSQL Connector/Net,因此像Take和FirstOrDefault这样的东西在LINQ语句本身中不受支持,我选择在迭代期间使用这些方法,因为它不会引发异常)
问题是,当所有3个字段(游戏,收件人和评论)都存在时.我得到了异常"对象必须实现IConvertible".但是,如果我删除3个字段分配中的任何一个(无关紧要),它就可以正常工作.谁知道这里发生了什么?
提前致谢!
瑞安.
| 归档时间: |
|
| 查看次数: |
1155 次 |
| 最近记录: |