这是我的代码
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);
}
我得到的错误是: LINQ to Entities
中仅支持无参数构造函数和初始值设定项我不知道如何解决这个问题。有什么想法吗?
答案 0 :(得分:10)
在进行查询之前构建Guid :
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
};