English 中文(简体)
与林克至锡克的当地顺序比较
原标题:Compare with a local sequence in Linq to Sql

下面是:

internal class DateInterval{
        public DateTime StartDate { get; set; }
        public DateTime EndDate { get; set; }
}

我想在数据库上进行所有活动,这些活动至少与的匹配。

理想的情况是:

var query = from _event in db.GetTable<Event>()
            where dates.Any(d => d.StartDate <= _event.Date && d.EndDate > _event.Date)
            select _event;

但我有以下例外:

Local sequence cannot be used in LINQ to SQL implementation of query operators except     the Contains() operator

由于<代码>. 连续()方法只接受确切结果而不是时间序列,是否可实现预期结果?

最佳回答

你在此的基本选择是使数据库中的查询得以实现,然后与记忆中的清单进行比较。

var query = yourSqlQuery.AsEnumerable() // forces* evaluation
                        .Where(...) // happens in memory 

Obviously, the more filtering you can perform at the DB in order to pull less results into memory, the better, but in this case, your options are limited.

var query = db.GetTable<Event>().AsEnumerable().Where(event => dates.Any(...)); 

* 推迟到>>>>>>>。 查询结果,但从附加<代码>过滤 在将记忆中发生时,在<代码>可计算(之前的部分将出现在数据库中。

问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签