Click here to Skip to main content
15,885,914 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Should an ORM implementation query the DB as soon as an active record is
created in order to check that the queried row exists in DB, or is it OK to
throw an exception later when attempting to access a field (for an
nonexistent row)?
Posted
Comments
Sergey Alexandrovich Kryukov 4-Sep-15 11:59am    
Whichever reduces exception handling; I would rather suggest — later.
—SA
Victor Porton 4-Sep-15 15:46pm    
What do you mean by the word "reduces"?
Sergey Alexandrovich Kryukov 4-Sep-15 16:03pm    
Less exception handling. Exception handling is invented to reduce the amount of code handling exceptional situations.
In general, you are raising a big topic. There is some big misconception that programming should be defensive. People think so because, for example, this is what they were taught at school. But development of relational model, SQL and exception handling demonstrates that programming can be and often should be offensive. It's stupid to checkup if the file exists. Instead, you can just use the file via, say, StreamReader and face exception when it fails. It's even deeper in SQL. Instead of checking that something exists, it's better to find it by a single query. And so on...

Now, there is a lot of heated discussions against ORM, which is considered as anti-patten itself. I don't have a certain opinion on this topic, but some of the arguments blame it or being offensive. Like in the known meme: "You make that sound like a bad thing".

Doing things later makes programming more offensive, and I think it's generally good.

I don't want to publish a formal answer, because the issue is deep and ambiguous. It's just some food for thought.

—SA
ZurdoDev 4-Sep-15 15:43pm    
Reply to the comment so that the user is notified.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900