none
The data reader is incompatible with the specified type error RRS feed

  • Question

  • Hi,

    There are many Stored procedure in my database whose output data are relatively same .
    Lets say
    SP1 output's : d1,d2,d3
    SP2 output's : d2,d3
    sp3 output's : d1,d3,d4

    So, what i thought is to create a Single Complex type (Say C1)  in Entity Data Model that contains all these members d1,d2,d3,d4,d5 with appropiate types and all function imports return type set to C1.
    I thought this should work , but this gave error like this :

    The data reader is incompatible with the specified 'C1 ComplexType'. A member of the type, 'd4', does not have a corresponding column in the data reader with the same name.

    My mindset was that with a single type i could get return collection from all function imports .I thought whereever applicable appropiate column will get values and if a column has no corresponding return data from stored procedure it will be simple set to null.
    But this did'nt worked . Maybe there can any way to achive this .
    Have anyone faced this situation , is there solution to these types of problems ?

    Tuesday, October 16, 2012 3:09 PM

Answers

  • Hi bootstrap2;

    The schema of the result set returned by the SP must match exactly that of the type you are filling. If they are not you will receive the exception you are getting. If you need to achieve this then I would try making all the SP's return the same number of columns with the correct data type for each and return nulls for those column that are not being returned for that SP. In this way you will always be matching the schema with the type in your code.

      

    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    Tuesday, October 16, 2012 7:34 PM

All replies

  • Hi,

    Stored Procedure 1 (SP1) : This outputs d1,d2,d3 data

    Stored Procedure 2 (SP2) : This outputs d2,d3 data

    Stored Procedure 3 (SP3) : This outputs d1,d3,d4 data

    Fact is that data type of d1 is same in all procedure . Similarly , data type of d2 , d3 and d4 are same in all procedure .

    That's way i thought that to put all data as scalar properties in a Single Complex Type and reuse the same Complex Type in all Function Import as return type . It may be possible that scalar property which is not required by a Function Import be assigned a null value !

    e.g., when calling function import for SP1 that does not require d4 property , so its value in each object in return object be assigned null.

    But , this is not the default behavior .That gave error . 

    So, is there any way to achieve this ?

    Tuesday, October 16, 2012 7:02 PM
  • Hi bootstrap2;

    The schema of the result set returned by the SP must match exactly that of the type you are filling. If they are not you will receive the exception you are getting. If you need to achieve this then I would try making all the SP's return the same number of columns with the correct data type for each and return nulls for those column that are not being returned for that SP. In this way you will always be matching the schema with the type in your code.

      

    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    Tuesday, October 16, 2012 7:34 PM
  • Hi,
    ok fine .Thanks for reply and confirming that it is not possible .
    Similar to that i have yet another problem , but this time for parameters.
    Here is the link for that thread.Kindly have some idea about this .
    Wednesday, October 17, 2012 7:14 AM
  • Hi;

    I will have a look at your other question. Kindly please close this question by accepting the solution.

    Thanks


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    Wednesday, October 17, 2012 3:18 PM