115
votes
Should I check if something exists in the db and fail fast or wait for db exception
Checking for uniqueness and then setting is an antipattern; it can always happen that the ID is inserted concurrently between checking time and writing time. Databases are equipped to deal with this ...
44
votes
Accepted
Should Entity Framework 6 not be used with repository pattern?
To get this out of the way, I am a big proponent of Entity Framework, but it does come with some drawbacks that you need to be aware of.
I also apologize for the long answer, but this is a very hot ...
39
votes
Should I check if something exists in the db and fail fast or wait for db exception
I think what you call “fail fast” and what I call it is not the same.
Telling the database to make a change and handling the failure, that is fast. Your way is complicated, slow and not particularly ...
22
votes
Accepted
Is it an anti-pattern to create ORM entities based on existing database schema?
Reverse engineering was created for precisely your kind of situation. It was meant to be a time-saving tool when using an ORM with an existing database. The tool can do in a few minutes what a human (...
16
votes
Should I check if something exists in the db and fail fast or wait for db exception
This started as a comment but grew too large.
No, as the other answers have stated, this pattern should not be used.*
When dealing with systems that use asynchronous components, there will always ...
9
votes
Accepted
How to write dynamic (non ORM) repositories that can return only the necessary data without creating many methods or data-objecs?
It would be wasteful to always fetch the entire objects.
First I would question this. If your objects are well-designed and not too bloated, the performance and memory overhead of fetching them ...
7
votes
Accepted
Routing all SQL queries through a single micro-service
What would be the drawbacks of such an architecture?
Single point of failureness.
Coupling that microservice to all others, hindering deployments and versioning.
That DB access service is going to be ...
6
votes
Unifying programming and database query
This is my opinion. While I do see where are you coming from, I just can't see it happening from design perspective.
Data persistence is extremely complex subject. And so are programming languages. ...
6
votes
Accepted
Object that can set its own subclass/amend its methods with subclass?
Clients have different kinds of contracts, their data format
remains the same, however, the underlying dynamics are different.
According to this statement, you implement the single table inheritance ...
6
votes
Is it an anti-pattern to create ORM entities based on existing database schema?
Both patterns are supported. Code first versus Model first. If you have an opiniated database administrator(s) or strong SQL skills one may choose Model first. If one has less SQL expertise, ...
5
votes
Advice on AggregateRoot boundaries
There are two different aspects in your question: where should the boundary be in your domain model? and how to implement your model?
The boundaries in the model
The definition of an aggregate is:
A ...
5
votes
Unifying programming and database query
Yes (not me). It was called MUMPS.
According to this this former SE.SE question, or this article, MUMPs was not very well designed. But is was indeed used in the health industry (and I guess there ...
5
votes
Unifying programming and database query
It seems like you're making some major assumptions. For example, you're assuming that everyone is writing to relational databases. That's simply not the case, there are lots of examples of databases ...
5
votes
Unifying programming and database query
There are indeed multiple systems which unify database and programming language into a single environments.
Smalltalk is probably the closest to what you describe. Object in memory are persisted in ...
5
votes
Accepted
Should I check if something exists in the db and fail fast or wait for db exception
Rather a confused question, but YES you should check first and not just handle a DB exception.
First of all, in your example you are at the data layer, using EF directly on the database to run SQL. ...
5
votes
Accepted
When using an ORM when should I sacrifice performance for convenience?
The way you make this decision is by optimizing when you need to.
There are many scenarios (e.g. a single-record data-entry form) where pulling all of the fields is perfectly acceptable, since you're ...
5
votes
Accepted
Encapsulation and input validation duplication
Could you tell me please, is the validation in Basket.ChangeItemQuantity redundant?
Yes it's redundant. But that's the least of your problems.
Semantically it's weird for an Item to know how many of ...
5
votes
Accepted
Any solid reason to have getters/setters in entities? ORM, Doctrine
I used to eschew getters and setters, I would "Pah" those who put forward the reasons why they are better for the kind of reasons you suggest.
Now I use them all the time without a second thought. ...
4
votes
The Open/Closed Principle, how does it work for adding entities?
It's not your changes that told the open/closed principle to go to hell. It was the design. OCP says it's a better design that allows change to come, not from rewriting code, but from adding new code....
4
votes
Best practice for object relation mapping to execute delete/update
My question here this, for the purpose of convenience and ease of maintenance, is it worth to follow ORM pattern and ignore the performance trade off?
It depends, mainly on the following things:
does ...
4
votes
How do I approach structuring when to read/write objects to db?
You can take a look at Unit of work:
[A unit of work] maintains a list of objects affected by a business transaction and coordinates the writing out of changes and the resolution of concurrency ...
4
votes
Should Entity Framework 6 not be used with repository pattern?
Entity framework is not a full abstraction, only a partial one. It only abstracts away the querying of the data.
For example, what if you have an Order entity, but as your application grows, it ...
4
votes
Accepted
Maintaining parallel libraries: Binary files access + Metadata Database ORM design
Take a step back.
If there is something in common between the two API's then they are discussing the same thing.
You can extract that sameness into a library which is expanded on by the ...
4
votes
Accepted
Select from many-to-many in one query
Yes.
You can issue a query that returns
customer_name | customer_id | item_id | item_name
--------------|-------------|---------|----------
bob | 0 | 0 | chair
bob |...
4
votes
Accepted
Using orm events or database triggers
It is an architectural choice.
Either you do it in the ORM. But the you should make sure that the relevant database objects are only accessed outside of your code via a service that also uses the ORM.
...
4
votes
Is it an anti-pattern to create ORM entities based on existing database schema?
Neither is an anti pattern, they are just two different mindsets regarding database integration:
The application centric: The database is just a service for persisting application state. The role of ...
4
votes
Is it an anti-pattern to create ORM entities based on existing database schema?
Who "owns" the database? Is it your app? Or some other business?
Do you have a continuity plan to support the old app while you develop new one?
Unless the database is for your app only, and ...
3
votes
Database modeling. Many to Many relationships. Link tables
Let us ignore the fact your solution 2 is not semantically equivalent to the first one (since it will allow only to model the status interested for a user who has a subscription for that particular ...
3
votes
The Open/Closed Principle, how does it work for adding entities?
I think you've misunderstood the purpose of the open/closed principle (which I'm going to abbreviate OCP for the rest of this). The OCP doesn't mean that if you ever have to add an entity that no ...
3
votes
How can I model unknown and an unknown number of attributes on an object?
Django can store JSON directly in the database with JSONField.
It is supported in some databases only, but https://docs.djangoproject.com/en/dev/ref/contrib/postgres/fields/#jsonfield and http://...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
orm × 279database × 55
entity-framework × 32
design-patterns × 31
domain-driven-design × 29
c# × 28
object-oriented × 27
design × 25
sql × 24
java × 23
php × 21
database-design × 21
architecture × 19
domain-model × 14
hibernate × 14
python × 11
nhibernate × 11
performance × 10
relational-database × 10
entity × 10
object-oriented-design × 9
repository × 9
persistence × 9
jpa × 9
.net × 8