M
Matt C.
I have a file-parse/insert-into-db app I'm writing. Currently I'm using
foreign key constraints with lookup tables to ensure all inserted code
values are on the permitted list. If an invalid code is sent, I catch the
SqlException and log the error to a different table.
There are some weaknesses with this approach, and I'd like to detect the FK
violations on the client prior to the insert. I figure this means drawing
down all the lookup tables and running a client-side validation on each one
(blah). What I'm not sure about is the best way to managing this lookup
data in ADO.NET. I'm considering two general approaches:
1) Use stored procedures to pull down each lookup table as a DataTable.
Define a PK on each DataTable (blah). Use Rows.Find to check each value as
part of the client-side validation. (Could also use DataView, too, I guess,
and skip the PK def?)
2) Pull down lookup data as above, but load the relevant codes from each
lookup table into a Hashtable, with each code as a key. Then use
Hashtable.HasKey in the client side validation.
Presumably 2) would run faster at validate time, and it skips the annoying
PK definition process. I'm leaning that way, but I've not used the
Hashtable much, there might be issues I'm not aware of.
Anyway, I'd like to solicit other's opinions, including suggestions on
completely different approaches. I can't be the first person who's tried to
implement something like this; if there's a best practice I'm happy to
follow it.
Matt
foreign key constraints with lookup tables to ensure all inserted code
values are on the permitted list. If an invalid code is sent, I catch the
SqlException and log the error to a different table.
There are some weaknesses with this approach, and I'd like to detect the FK
violations on the client prior to the insert. I figure this means drawing
down all the lookup tables and running a client-side validation on each one
(blah). What I'm not sure about is the best way to managing this lookup
data in ADO.NET. I'm considering two general approaches:
1) Use stored procedures to pull down each lookup table as a DataTable.
Define a PK on each DataTable (blah). Use Rows.Find to check each value as
part of the client-side validation. (Could also use DataView, too, I guess,
and skip the PK def?)
2) Pull down lookup data as above, but load the relevant codes from each
lookup table into a Hashtable, with each code as a key. Then use
Hashtable.HasKey in the client side validation.
Presumably 2) would run faster at validate time, and it skips the annoying
PK definition process. I'm leaning that way, but I've not used the
Hashtable much, there might be issues I'm not aware of.
Anyway, I'd like to solicit other's opinions, including suggestions on
completely different approaches. I can't be the first person who's tried to
implement something like this; if there's a best practice I'm happy to
follow it.
Matt