【问题标题】:Linq to Entities-- Havine a Guid in the where clause throws errorLinq to Entities——在 where 子句中有 Guid 会引发错误
【发布时间】:2009-09-22 06:50:04
【问题描述】:

这是我的代码

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 仅支持无参数构造函数和初始化程序

我不知道如何解决这个问题。有什么想法吗?

【问题讨论】:

  • 错误信息非常明显。 :)

标签: c# linq


【解决方案1】:

在您进行查询之前构建 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
     };

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-02-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-15
    • 2011-10-18
    • 1970-01-01
    • 2011-11-25
    相关资源
    最近更新 更多