I have two same procedures in two DB, by same I mean:
- Same name
- Same parameters name & type
- End with a select returning same columns types & names (If I put a
SELECT ... INTO tableit generates the exactly same table).
The only thing which differs is the code building the sql query for the final select.
If I use EF on Database 1 it works as intended, but if I run the code on Database 2 it ends on error:
The data reader is incompatible with the specified ‘Ctx.Procedure_Result’. A member of the type, ‘FooId’, does not have a corresponding column in the data reader with the same name.
I’m using:
- Entity Framework 4.2
- Visual Studio 2010
- Sql Server 2008 R2
I don’t have enough knowledge of EF internals to understand why this is happening.
My idea is that there must be some columns types/names sniffing mecanism which doesn’t sniff the same stuff.
Edit 1:
The procedure doesn’t “return” a table type it just “select” some rows.
This select result is mapped to a ComplexType in the EDMX.
Feel free to ask for more details.
My fault, as suggested I traced the EF queries with SQL Server Profiler.
In fact EF was using NULL in an optional parameter which destroyed the sql query inside the procedure (‘select … ‘ + NULL => NULL).
With a NULL query the procedure select no column at all and it crashes the EF data reader.