Entity Framework 4 exception not being thrown / caught

妖精的绣舞 提交于 2020-01-25 06:32:12

问题


I am connecting to a MySQL database from Visual Studio 2010 using Net/Connector.

This is the entity framework 4 linq query:

        int timeThreshold = 5;
        DateTime cutoffTime = DateTime.Now.AddMinutes(-timeThreshold);

        try
        {
            using (var context = new myEntities())
            {

                var unprocessedMessages = from m in context.messages
                                          where m.createdDate < cutoffTime
                                          select m;

            }
        }
        catch (Exception e)
        {
            string exceptionString = e.InnerException.ToString();
        }

The Results view in the expanded unprocessedMessages displays an exception:

  • base {"An error occurred while executing the command definition. See the inner exception for details."} System.Data.EntityException {System.Data.EntityCommandExecutionException}

I am trying to see what the inner exception is. However, the catch block is never entered. What is happening here?

来源:https://stackoverflow.com/questions/3505616/entity-framework-4-exception-not-being-thrown-caught

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