GithubHelp home page GithubHelp logo

Comments (6)

wyshmily avatar wyshmily commented on May 15, 2024

And I don't think such specifications are needed by the applicationcore.

Want some guide, thanks!

from eshoponweb.

ardalis avatar ardalis commented on May 15, 2024

Specification is meant to encapsulate complex queries. If you just want to know if a record exists, you can do a GetById() and see that it returns null - no Spec needed.

from eshoponweb.

wyshmily avatar wyshmily commented on May 15, 2024

but in my case, the query is not by id, but other field like studentnumber

from eshoponweb.

ardalis avatar ardalis commented on May 15, 2024

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.

from eshoponweb.

wyshmily avatar wyshmily commented on May 15, 2024

In fact it would not cause an exception, because I use soft delete, with a IsDeleted field in each table.
Such checks can only be performed manually since there is no unique index.
So the answer is creating specs to do the job?

from eshoponweb.

ardalis avatar ardalis commented on May 15, 2024

If you're already set up to use Specifications (that is, your Repository can accept an ISpecification<T> or similar) then yes, a spec would do the job easily. If you're not using the Specification pattern or don't want to use it for this case, the simplest approach would be to create a method on your interface (example: IStudentRepository has method GetStudentByStudentNumber(int number) ). The reason I don't prefer this approach is it results in bigger repositories and more repository interfaces and classes. I'd rather have the specification classes, which better follow SRP, than many inconsistent IWhateverRepository implementations, given the choice. Hope that helps.

from eshoponweb.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.