-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Question about the repository and specification design #71
Comments
And I don't think such specifications are needed by the applicationcore. Want some guide, thanks! |
Specification is meant to encapsulate complex queries. If you just want to know if a record exists, you can do a |
but in my case, the query is not by id, but other field like studentnumber |
In that case if you're already using specs in your design, it would be easy to create a spec for StudentByStudentNumber(int studentNumber) that would include the required lambda expression to fetch student(s) with that number. Alternately unless you expect it to be a regular occurrence for student creation to result in potential duplicates, you could just attempt the create and catch the exception when the record already exists. If it truly is an exceptional condition, this would be an appropriate design as well. |
In fact it would not cause an exception, because I use soft delete, with a IsDeleted field in each table. |
If you're already set up to use Specifications (that is, your Repository can accept an |
The repository and specification design looks good, but when I use it in my work, I found it hard to handle when the logic is a little more complicate.
For example, when my api accepts a new Student object For create, I have to check if the student'scardnumber already exists, do i define a specification to do this check? It's annoying to do a lot of such works.
The text was updated successfully, but these errors were encountered: