RSS 2.0
# Wednesday, January 09, 2008

I've been doing stuff with LINQ to SQL for a while now and there's one thing that keeps bugging me: Proper exception handling. IMHO LINQ to SQL should encapsulate the database. I mean, I don't care which database (SQL Server, Oracle, whatever) I'm working with, but if I call SubmitChanges on the DataContext, I'll get a SqlException if it fails on the database. I know that currently LINQ to SQL only supports SQL Server, but the model is just as valid for any other (relational)database. To my surprise there is no LinqException or something that encapsulates the SqlException, so now I have to write code that is aware of the fact that I'm dealing with SQL. You can of course solve this by using the Exception Handling Application Block, so you don't deal with specific exceptions in code, but it still feels funky.

Wednesday, January 09, 2008 11:21:11 AM (W. Europe Standard Time, UTC+01:00)  #    Comments [2] -
.NET | English | LINQ
Wednesday, January 30, 2008 12:24:20 PM (W. Europe Standard Time, UTC+01:00)
Michiel,

Heb je ook een idee hoe je linq exceptions kan onderscheiden/handig afvangen. Ik heb bijvoorbeeld een veld in mijn tabel waarin ik unieke waarden opsla. Dubbele gegevens mag dus niet, doe je het wel dan volgt een exception. Hoe kan ik zo'n exception het beste afvangen? Eerst een functie schrijven of de waarde al bestaat? En dat voor ieder uniek veld/tabel? Of kan dat ook ineens/handiger?

Bedankt!
Boah
Wednesday, January 30, 2008 12:45:46 PM (W. Europe Standard Time, UTC+01:00)
Boah,

Wat ik nu gedaan heb is een base class gemaakt voor interacties met LINQ. Hierin zit o.a. een SubmitChanges methode die SqlExceptions afvangt en een eigen exception teruggeeft. Iedere business class die wijzigingen doet op LINQ data is gebaseerd op die base class en roept niet de DataContact.SubmitChanges, maar de eigen SubmitChanges aan. In de base class zit dus alle exception handling logica en daar zou je dus bijvoorbeeld kunnen controleren of een exception gegooid is omdat er dubbele waardes zijn. Die check hou je "gewoon" in de key/index instelling van je tabel.
All comments require the approval of the site owner before being displayed.
Name
E-mail
Home page

Comment (Some html is allowed: a@href@title, strike) where the @ means "attribute." For example, you can use <a href="" title=""> or <blockquote cite="Scott">.  

Enter the code shown (prevents robots):

Live Comment Preview
Sign In

Archive
<February 2012>
SunMonTueWedThuFriSat
2930311234
567891011
12131415161718
19202122232425
26272829123
45678910
About
This is the blog of Michiel van Otegem, a Senior Software Architect with Sogeti Netherlands, and author of several books and numerous articles on (ASP).NET, XML, and related technologies.
Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2012
Michiel van Otegem
All Content © 2012, Michiel van Otegem
DasBlog theme 'Business' created by Christoph De Baene (delarou)