0

I started using Entity Framework 4.3.1 with code first approach.

I want to avoid application crash when database server is shut down or unavailable catching specific exceptions. Imagine this short sample piece of code:

using (var db = new MyContext())
{
     var people = new People();
     db.People.AddObject(people);
     db.SaveChanges();
}

When server is shut down, I receive ProviderIncompatibleException. If I try to modify code catching ProviderIncompatibleException like this

using (var db = new MyContext())
{
     try
     {
         var people = new People();
         db.People.AddObject(people);
         db.SaveChanges();
     }
     catch(ProviderIncopatibleException)
     {
     }
}    

I receive compiler error "The type caught or thrown must be derived from System.Exception". How can I catch most specific Exception using Entity framework? Thank you for help.

4

1 回答 1

1

类名中有一个错字 - 您在不兼容中漏掉了一个“m”。

再试一次ProviderIncompatibleException

于 2012-06-06T15:04:37.693 回答