Here's an interesting problem. Is there a way to write some code using LINQ to SQL which is capable of performing a table UPDATE knowing only that the table it is given contains columns x, y, z but not knowing at compile time which table it is dealing with?
I have several tables in my DB schema which share some columns and I need to apply a set based UPDATE operation which is identical in its logical procedure regardless of which one of the tables we're dealing with.
Here's a simple example: say you have 3 tables which implement an adjacency model hierarchy (ie each row contains a primary key ID and a self-referencing parent ID column). Each of the tables also has a 'Disabled' boolean flag. When I disable an instance of any of these entities, it should cascade through the child items, i.e.
UPDATE MyTable SET Disabled = 1 WHERE ID = @ID or Parent_ID = @ID
I don't want to be writing these kind of LINQ statements for each entity, it violates DRY. It might seem trivial with this example, but as the example gets more complex you're duplicating increasing amounts of code. I'm sure it must be possible using an interface and perhaps generics, but I'm struggling to come up with an elegant solution.