Hi
Thanks for the quick reply!
Yes, you're right - i can do largely what I want using projections, writing pretty much the code you had in your example.
However, there are a couple of problems with this:
1. It requires me to write a reasonable chunk of repetitive code myself i.e. lots of very similar lines, and I have to manually write this code for every single stored proc in my database (we have hundreds).
2. It still requires me to explicitly know what order the columns are returned in by the stored proc (e.g. first column is customer ID, second column is name etc), and I also have to know all the data types. It would be very easy to make a mistake and not know e.g accidentally get a datatype, or column position or column name wrong.
3. If somebody changes the stored proc without me knowing and inserts a new column or changes an existing one, my code will only fail at runtime or worse, might continue to work but give the wrong results.
My thinking is that given LLBLGenPro can determine the names and types of input params, could it not ALSO derive the output column names and data types, and generate a corresponding class as well, meaning that all stored proc calls return a collection of strongly typed row objects instead of a DataTable? I believe there would be big benefits:
1. All my client code would then be working entirely with collections of objects, rather than rows in data tables ie. much more OO.
2. Having strongly-typed collections returned by stored procs makes the client code much clearer e.g I can go
resultList.CustomerName
instead of
resultTable.rows[0].columns[2].ToString()
- Having strongly-typed collections returned by stored procs would also allow the compiler to find datatype etc bugs at design time e.g. if my client code is trying to treat CustomerName as an Integer, the compiler would flag that as a compile error, rather than me having to track down a Type Conversion error at runtime. Every bug I can get the compiler to eliminate for me is one less thing to go wrong at run time..!
- If somebody changes a stored proc to insert or change column, I would know all about it as soon as I regenerated the DAL code and tried to compile my project, because the strongly typed collection would have changed.
I realise that to do this, LLBLGEN would probably have to parse the T-SQL in some fashion, which is probably tricky, but I think CodeSmith already does this in some fashion? Anyway, I am keen to hear your thoughts on this whole plan!
Cheers
Brett