在where表达式中使用Guid.Empty挂起Linq查询 [英] Hanging Linq query with Guid.Empty in the where expression

查看:116
本文介绍了在where表达式中使用Guid.Empty挂起Linq查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用以下代码时遇到问题:

I'm having an issue with the following code:

    private void DataPortal_Fetch(TaskCriteria criteria)
    {
        using (var ctx = ContextManager<Gimli.Data.GimliDataContext>
                    .GetManager(Database.ApplicationConnection, false))
        {
            this.RaiseListChangedEvents = false;
            this.IsReadOnly = false;

            IQueryable<Data.Task> query = ctx.DataContext.Tasks;

            if (criteria.ReadyForPricing)
            {
                query = query.Where(row => row.IsPriced != true);
                query = query.Where(row => row.Status == (int)TaskStatus.Closed);
                query = query.Where(row => row.InvoiceId == Guid.Empty);
            }

            if (criteria.ReadyForInvoicing)
            {
                query = query.Where(row => row.IsPriced == true);
                query = query.Where(row => row.Status == (int)TaskStatus.Closed);
                query = query.Where(row => row.InvoiceId == Guid.Empty);
            }

            var data = query.Select(row => TaskInfo.FetchTaskInfo(row));

            this.AddRange(data);

            this.IsReadOnly = true;
            this.RaiseListChangedEvents = true;
        }
    }

我的Web应用程序调用此方法时,如果我不注释以下行,则始终挂起:

My web application, when it calls this method, always hangs if I don't comment out the following line:

query = query.Where(row => row.InvoiceId == Guid.Empty)

知道为什么会这样吗?

推荐答案

以下代码可以正常工作...有趣的是...为什么要这么做?

The following code works ... interestingly enough ... any idea of why?

query = query.Where(row => row.InvoiceId == new Guid("00000000-0000-0000-0000-000000000000"));

这篇关于在where表达式中使用Guid.Empty挂起Linq查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆