我正在使用TransientFaultHandling.RetryPolicy
. 我想知道重试策略是否足以仅连接实体框架。连接实体后,我将在多个地方使用实体。在打开连接和使用连接之间,如果连接丢失怎么办?重试策略会处理连接吗?
连接类
static class Azure
{
static RetryPolicy policy = new RetryPolicy<MyRetryStrategy> (5,TimeSpan.FromSeconds(2), TimeSpan.FromSeconds(2));
public static CrmEfEntities ConnectCustomerEntity()
{
CrmEfEntities customerEntity = null;
policy.ExecuteAction(() =>
{
customerEntity = new Entities(ConnectionStringCustomerDB());
string federationCmdText = @"USE FEDERATION Customer_Test_Federation(TestId =" + testId + ") WITH RESET, FILTERING=ON";
customerEntity.Connection.Open();
customerEntity.ExecuteStoreCommand(federationCmdText);
});
return customerEntity;
}
}
我在控制器中调用上述方法,如下所示:
public class EmployeeController : Controller
{
private static readonly CrmEfEntities _db = Azure.ConnectCustomerEntity();
public ActionResult Index()
{
var employeeList = GetEmployeeDetails().ToList();
return View(employeeList);
}
private static IEnumerable<EmployeeModel> GetEmployeeDetails()
{
var employee= from emp in _db.Employees
from coun in _db.Countries
where emp.CountryId == coun.Id
select new CompanyDetailsModel
{
Id = emp.Id,
Name = emp.Name,
countryName=coun.Name
};
return employee;
}
}