엔티티에 CRUD 작업을 제공하는 클래스가 있습니다. 컨텍스트를 클래스의 모든 메서드에서 액세스 할 수있는 전용 멤버로 사용하고 있습니다.Entity-framework의 컨텍스트 처리
public class CustomerService
{
private CeoPolandEntities context;
public CustomerService()
{
context = new CeoPolandEntities();
}
public bool IsCustomerValid(string userName,string password)
{
Customer customer;
customer = context.CustomerSet.FirstOrDefault(c => c.UserName == userName
&& c.Password == password);
return customer == null ? false : true;
}
public bool IsUserNameValid(string userName)
{
Customer customer;
customer = context.CustomerSet.FirstOrDefault(c => c.UserName == userName);
return customer == null ? true : false;
}
}
컨텍스트를 사용하면 적절합니까? 스레드 안전하고 concurency 안전한가요 ??
ASP.NET 응용 프로그램입니다.
그래서 인스턴스를 처음로드 메서드를 호출 한 다음 저장 메서드, 그게 나쁜가요? 왜 ? – user137348
아니, 나는 당신이 스레드 (asp.net 요청을 작성하는 대신)를 작성하는 경우 다음 즉, 그것은 여전히로드를 때려서 이미로드 중일 수 있습니다 ... 더 일반적인 것은 u는 노력하고 있다는 것을 의미합니다 동일한 문맥 인스턴스로 여러 것을 동시에로드하십시오. 그것의 완벽하게 k, 같은 asp.net 요청을로드하는 동안 동일한 인스턴스를 사용하여 물건을 저장하고 18 시간을 절약 할 수 있습니다. – eglasius