Questions tagged [specification-pattern]

Allows business rules to be recombined by chaining the business rules together using boolean logic. The pattern is frequently used in the context of domain-driven design.

114 questions
0
votes
2 answers

Fetching the count of child entities with EF Core instead of the full entity using a generic repo with specification pattern?

When I fetch a "Users" info for their profile page. I'm fetching multiple child entity collections from the "User" (parent) entity to either get info from it (ex. images) or I'm fetching them just to get a count (ex. Likes) Problem - When fetching…
chuckd
  • 13,460
  • 29
  • 152
  • 331
0
votes
1 answer

Is there a way to allow for inheritance inside Specification pattern generics?

First of all, sorry for the question's title, it was hard to come up with a way to phrase it, let me explain the situation. I am using the Specification pattern to perform db filtering with Entity Framework, and avoid doing it on memory (I roughly…
0
votes
2 answers

Clojure.Spec derive or alias another spec

I'd like to use clojure spec to build up a set of type constraints that can be aliased or further constrained by other specs. For example, I might have many fields that all need to be valid sanitized markdown. The following example works for…
farlee2121
  • 2,959
  • 4
  • 29
  • 41
0
votes
1 answer

DDD modelling settings as Value Objects

I am attempting to build an application in a DDD way. Imagine the Aggregate root is a 'Page' which has other aggregates such as Author, Commenter, Comments, Status etc... A page can also have various settings such as: Private page Allow…
0
votes
1 answer

Spring Data Specification orderBy subquery

On my MySql project I got this particular model with 3 entities: Prodotto with many childs QuotaIngrediente, that in turn is Many-to-One child of Ingrediente too. All my relationships are bi-directional. All of them got an autogenerated integer Id…
4javier
  • 481
  • 2
  • 7
  • 22
0
votes
1 answer

Using the speicifcation pattern as a validation layer?

I have only seen the specification pattern used to retrieve data, but not to validate it. A colleague suggested I can use the specification pattern to “validate” an object so it does not become invalid when saving changes. As an example, say we…
DDiVita
  • 4,225
  • 5
  • 63
  • 117
0
votes
1 answer

Join 2 Tables using Spring Boot JPA Criteria Specification and Predicate

I'm trying to create a criteria to retrieve Rows from 2 tables (UserDetail, Vehicle). A UserDetail has reference to Vehicle. My objective is to retrieve a list of specified field from both Tables, given an UserDetail id. In @Query was easy to do but…
Sadina Khatun
  • 1,136
  • 2
  • 18
  • 27
0
votes
0 answers

How should the specification pattern handle null candidates?

I am just wondering if there is a recommended strategy for dealing with null candidates in the specification pattern. As I see it, there are two possible strategies: Throw an exception if the candidate is null. Return false for cases where null is…
Matthew Layton
  • 39,871
  • 52
  • 185
  • 313
0
votes
1 answer

Spring Data JPA - Query with Specification (Join and IN)

I've assembled the following class Specification: public ItemVendedorSpecification(String descricao, List categorias, List fabricantes, List vendedores) { super(); this.descricao = descricao; …
0
votes
1 answer

JPQL aggregate functions with Specifications

I need to make a JPQL query with aggregate functions, using Specifications. I would like something like myQuery="select sum(et.durationMinutes/et.percent) from EmployeeTimekeeping et" myQuery.where(specifications) myQuery.getResultList(); I'm…
0
votes
1 answer

Reflection issue: NoSuchMethodException ...specification.SearchCriteria, [Ljava.lang.String;)

Well, NoSuchMethodException is normally well self-explaining. Unfortunately, in my case, I couldn't even guess why I am getting such error. I am taking care a code from other developer and I must maintain it. It was designed with specification…
Jim C
  • 3,957
  • 25
  • 85
  • 162
0
votes
1 answer

Specification Pattern in a separate Project?

I'm planning to use "Specification pattern" to validate my domain objects in my solution. Where is the "correct" place to put the "specification" classes in my solution? Should I create a dedicated project that contains the "specification" classes,…
Henry Aung
  • 632
  • 1
  • 7
  • 15
0
votes
1 answer

How to implement specification pattern?

In my project; I have included specific pattern classes that are given below. I dont know how to implement this. These codes are included by previous developers. public interface ISpecification { Expression> SpecExpression {…
Pradees
  • 191
  • 1
  • 4
  • 17
0
votes
2 answers

Entity Framework 4 and Linq to Entities specifications: How to code it?

I threw down this code because it worked, but I really need to refactor to something acceptable. It accepts a set of query objects (strings that look like productid = 3) then adds them to my query. This only works for logical AND, but I will…
Zachary Scott
  • 20,968
  • 35
  • 123
  • 205
0
votes
1 answer

Using Automapper while using specification pattern to compose objects

A specification pattern can be used to compose objects as shown in the example below: IUser user = UserSpecification .ForPerson() .WithName("myname") …
Satyajit
  • 1,971
  • 5
  • 28
  • 51