Inspiriert von http://huyrua.wordpress.com/2010/08/25/specification-pattern-in-entity-framework-4-revisited habe ich beschlossen, alle nichttrivialen Abfragen über Spezifikationen zu schreiben. Aber у hat ein Problem, dass ich weiß nicht, wie eine Spezifikation in wenigen Funktionen zu nutzen:Spezifikationsmuster für das Repository?
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();
}
Ich möchte ein extrahieren Spezifikation“=> a.Email.ToUpper() == email.ToUpper() "Um es in beiden Funktionen zu verwenden, aber ich sollte es mit" email "(Funktionsparameter) parametrisieren. Wie kann ich das machen?