Linq to Entities - Havine a Guid in where argument generates an error

Here is my code

var bms = from b in context.bookmark join q in context.question1Set on b.bookmark_id equals q.question_id join u in context.userinfo on b.bookmark_ownerid equals u.user_userid where b.bookmark_ownerid == new Guid(userid.ToString()) && q.question_isdeleted == false //i think it dosent't like the new Guid select new { u.user_username, q.question_title }; foreach (var bm in bms) { question q = new question(); q.Username = bm.user_username; q.Title = bm.user_username; ql.Add(q); } 

Error I get: Only parameterless constructors and initializers in LINQ to Entities are supported

I have no idea how to fix this. Any ideas?

+4
source share
1 answer

Build Guid before executing the query:

 Guid userGuid = new Guid(userid.ToString()); // What type is userid anyway? var bms = from b in context.bookmark join q in context.question1Set on b.bookmark_id equals q.question_id join u in context.userinfo on b.bookmark_ownerid equals u.user_userid where b.bookmark_ownerid == userGuid && !q.question_isdeleted select new { u.user_username, q.question_title }; 
+10
source

All Articles