问题
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