Inspired by http://huyrua.wordpress.com/2010/08/25/specification-pattern-in-entity-framework-4-revisited i have decided to write all nontrivial queries over specifications.
But у encountered a problem that i dont know how to use one specification in a few functions:
public bool CheckAccountEmailExist(string email)
{
var emailExistSpec = new Specification(a => a.Email.ToUpper() == email.ToUpper());
return _accountRepository.GetBy(emailExistSpec).Any();
}
public bool CheckAccountEmailExist(string email, Guid exceptAccountId)
{
var emailExistSpec = new Specification(a => a.Email.ToUpper() == email.ToUpper());
var exceptAccountSpec = new Specification(a => a.Id != exceptAccountId);
return _accountRepository.GetBy(emailExistSpec.And(exceptAccountSpec)).Any();
}
I want to extract specification “a => a.Email.ToUpper() == email.ToUpper()” to use it in both functions, but i should parametrize it with “email” (function parameter). How can I do this?
For some reason I can’t view the page that you link to, but I imagine that it would go something like this:
Then: