Hi! I'm using linq to entities, and my entity model is sitting on top of MSSQL database.
I'm wondering if linq to entities throws SqlExceptions or not.
In other words, will the below code catch exception successfully if there was a problem connecting to the database?
If it doesn't, what's the best way to handle exceptions when using linq to entities?
using (MyUserEntities userEntities = new MyUserEntities(connectionString))
{
try
{
if (userEntities.Users.Any<User>(userInDB =>
userInDB.UserName == username))
{
//Do Something
}
else
{
//Do Something else
}
}
catch(SqlException e)
{
}
}