开发者

LINQ to SQL Delayed Evaluation Exception Handling

I have a LINQ to SQL/Unity/ASP.NET MVC/SQL Server application hosted on Azure. I am using Lazy Evaluation throughout the whole site. The Application is using a TCP connection to SQL Server and every so often I get a "A transport-level error has occurred when sending the request to the server." SqlException.

Well since the the query is getting materialized when it is called later in code, I can't just wrap a specific piece of code with a try/catch.

Is there a way that I can handle this exception by implementing an inte开发者_开发问答rface or attaching a delegate to the DataContext?


If you use the results from linq as-is, then you have to handle the error in the code that materializes the data. However, instead of simply returning the linq query results directly, you could wrap it in an IEnumerable implementation of your own design, which is free to implement whatever error handling you like. This way the code that consumes the IEnumerable doesn't have to handle the exception.


I think that the only way to fix this is to wrap the code that is triggering (materializing) the call to the SQL server in a try catch.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜