LINQ-to-entities: predicating on a DateTime field causes AccessViolationException

落爺英雄遲暮 提交于 2019-12-11 08:15:11

问题


I have the following code:

var dtThreshold = DateTime.Now.AddDays(-1);

using (var db = new TermbaseEntities())
{
    var tc = (from termChanges in db.st_element_audit_log
                where termChanges.element_type_id == (long) ElementType.Term
                      && termChanges.recorded > dtThreshold
              select termChanges).ToArray();

    ...
}

In the DB entities, st_element_audit_log.recorded is a DateTime property.

It's a fairly trivial statement, but running it causes the following exception:

Unhandled Exception: AccessViolationException

Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

If I comment-out the line

                      && termChanges.recorded > dtThreshold

Then that query runs without any problems, suggesting that MySQL ConnectorNET only has a problem with the DateTime predicate.

Can anyone suggest a way around this? I don't believe that it's poor coding on my side that's causing this (but I'm happy to be told if that is is the case), but I still need a way to retrieve those entities.

来源:https://stackoverflow.com/questions/26176400/linq-to-entities-predicating-on-a-datetime-field-causes-accessviolationexceptio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!