I have a challenge. We have a database that was originally designed to be used with VB6 and most of the functionality sits in stored procedures. I cannot make changes to the stored procedures as the old application will still need to work for a while and I do not have my own copy of the database that I can modify even briefly.
So is it possible to execute a stored procedure from EF and have it do it’s best to write the results into an array/collection of POCOs?
I’ve tried the database first approach and import but EF says the stored procedure does not return any columns and so cannot create a complex type. I’ve found there are ways to change the stored procedure to allow this to work but I cannot alter the database I’m using.
Another challenge is that the names of the columns in the results are things like ‘Date last changed’ in other words with spaces. How will EF try to map these? Would it become DataLastChanged or possibly Data_last_changed? Is there a way to mark my POCO with attributes to say how they are mapped?
What I was hoping for is something like
var resuls = efContext.ExecuteStoredProcedure<MyPOCOType>("spName",param1, param2, ...);
And have EF do it’s best to match the results to the type. Does such a thing exist? Incidentally we are using EF4 but I believe 5 is available to us.
I think I’ve cracked part of the problem for myself. The following snippet does what I need.
The confusing this is still the naming of the columns. They mostly seem to work but EF is not mapping the resulting column ‘Needs evaluation’ to the property NeedsEvaluation on my object.