Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Strange LINQ To Entities Exception

I am using a LINQ statement that selects from various tables information I need to fill some Post / Post Comment style records. I'm getting a funny exception saying that the object must implement IConvertible when I try to iterate the record set. The funny part about it is that it seems to only occur when the anonymous type I'm using to hold the data contains more than 2 generic collections.

//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 }     }; 

(Note: I am using MYSQL Connector/Net so things like Take and FirstOrDefault and things like that are not supported within the LINQ statements themselves, I have opted to use those methods during iteration as it does not raise an exception there)

The problem is, when all 3 fields (Game, Recipient, and Comments) are present. I get the exception "Object must implement IConvertible". BUT if I remove ANY one of the 3 field assignments (doesn't matter which one), it works just fine. Anybody know what's going on here?

Thanks in advance!

Ryan.

like image 908
SilverX Avatar asked May 05 '11 20:05

SilverX


1 Answers

This is a guess, but I think your anonymous type might be attempting to duck-type to an enum when you've got more than two queries. If that's happening, then you'll get this complaint about not implementing IConvertible, as enum implements IConvertible, and your anonymous type (now derrived from enum) does not implement the interface.

like image 150
Joe Avatar answered Sep 25 '22 01:09

Joe