Skip to main content
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 ...
Kilian Foth's user avatar
42 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 ...
Flater's user avatar
  • 52.9k
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 ...
gnasher729's user avatar
  • 46.1k
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 (...
Greg Burghardt's user avatar
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 ...
Mr.Mindor's user avatar
  • 309
12 votes
Accepted

When should I use stored procedures?

You have a couple of perfectly good scenarios already. There are lots of other reasons too. EF is really good at CRUD and at pretty straight forward reporting. Sometimes, though, EF is not the ...
Joel Brown's user avatar
  • 2,398
9 votes

Is ORM a bad tool for tree-like DB structures?

At the end of the day an ORM is just an abstraction which generates sql for you and maps the data to your objects. Saving(tm) you some 'boiler plate' code. So there is nothing that ORMs as a whole ...
Ewan's user avatar
  • 77.5k
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 ...
Doc Brown's user avatar
  • 210k
8 votes

Examples of mid/large-scale web-apps built without an ORM?

Stack Overflow uses a micro-orm. Unlike Hibernate, it's just a thin veneer around SQL queries. Answers to your questions: By writing a SQL query. It can vary from one line of code to about 40. ...
Robert Harvey's user avatar
7 votes

Is ORM a bad tool for tree-like DB structures?

Are ORMs simply a bad tool for creating complex DB-structures with many associations? No. As an example, Ruby on Rails uses ActiveRecord, which handles associations. In the example here : https://...
cmonkey's user avatar
  • 239
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 ...
Telastyn's user avatar
  • 109k
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. ...
Euphoric's user avatar
  • 37.6k
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 ...
Christophe's user avatar
  • 78.7k
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, ...
Jon Raynor's user avatar
  • 11.6k
5 votes
Accepted

Can I manage transactions in the UI

Technically, you are free to design the layers in your architecture however you want, but keep in mind transactions express some kind of business logic. If you put business logic into the UI, you ...
Doc Brown's user avatar
  • 210k
5 votes

Is ORM a bad tool for tree-like DB structures?

As noted in a least one other answer here, all ORMs are not the same. Some ORMs make very significant assumptions about how the database should be structured. The tooling should provide some support ...
JimmyJames's user avatar
  • 27.8k
5 votes
Accepted

ORM Inheritance mapping or not, how to map shared and specific properties for a set of related, real world objects

I would recommend avoiding that inheritance here especially when you are talking about letting that inheritance bleed down into your database - unless its an Object-Oriented database. But a typical ...
Stephen Byrne's user avatar
5 votes

Stored procedures or ORM in web?

The problem with Stored Procedures in your case are the multiple databases. As you point out. if you have to change a sproc you will then have to deploy that change to every database. Where as if ...
Ewan's user avatar
  • 77.5k
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 ...
Paul's user avatar
  • 3,317
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 ...
Doc Brown's user avatar
  • 210k
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 ...
JacquesB's user avatar
  • 59.9k
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 ...
Christophe's user avatar
  • 78.7k
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. ...
Ewan's user avatar
  • 77.5k
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 ...
Robert Harvey's user avatar
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 ...
candied_orange's user avatar
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. ...
Ewan's user avatar
  • 77.5k
4 votes

Examples of mid/large-scale web-apps built without an ORM?

You should check out Elixir's Ecto, which is a domain specific language (DSL) for interacting with (mostly relational) databases and writing queries. It goes well with the Phoenix framework, which ...
Gagandeep Bhatia's user avatar
4 votes

Examples of mid/large-scale web-apps built without an ORM?

There are various design patterns that are useful for applications that are not using ORM. I'd suggest reading through Martin Fowler's book, Patterns of Enterprise Application Architecture, which ...
Jules's user avatar
  • 17.8k
4 votes
Accepted

CRUD without an ORM

What we're doing on my team is using dedicated Data Access Object for putting our DB access code and storing the actual SQL code in stored procedures. I know it sounds old fashioned, but it's tried ...
Brandon's user avatar
  • 4,575
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....
candied_orange's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible