none
Course Manager Sample RRS feed

  • Question

  • currentStudent.PersonID is a value of 22

    'my code

           gradeGridView.DataSource = (From s In schoolContext.StudentGrades _
                                         Where s.StudentID = currentStudent.PersonID)

    'ms code
            gradeGridView.DataSource = schoolContext _
                .GetStudentGrades(currentStudent.PersonID)

    ALTER PROCEDURE [dbo].[GetStudentGrades]
                @StudentID int
                AS
                SELECT EnrollmentID, Grade, CourseID, StudentID FROM dbo.StudentGrade
                WHERE StudentID = @StudentID

    Why does my code work and not the code for the stroed procedure.  I have entered GetStudentGrades as a FunctionImport in the schoolEntites Mode. I get the sane error in thec code I created as well as the code as downloaded.

    Error

    "The data reader is incompatible with the specified 'SchoolModel.Person'. A member of the type, 'PersonID', does not have a corresponding column in the data reader with the same name."

     

    I am using Visul Basic Express SP 1 (with Windows 7)



    Sunday, July 10, 2011 2:40 PM

Answers

  • Hi andybrum;

    The error message you are getting:

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

    From the error message it sounds like when you did the Function Import of the stored procedure you selected as its return type as type Person where it should be StudentGread. The reason you are getting the error is that the Person type has a column called PersonID but the data reader has no such column therefore they are incompatible.

    To correct the issue go to the edmx designer and in the Model Browser -> EntityContainer SchoolEntities -> Function Import select the stored procedure right click on it select properties in the Return Type click on the ... and in the Edit Function Import select StudentGread as the Entities.

     


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    Sunday, July 10, 2011 5:06 PM
  • Hi Andy,

     

    Welcome to the forum.

    It seems you function mapping with a invalid type.

    The steps to use store procedure in EF:

    1、Add the Store Procedure to the Entity Model Designer using Update Mode from database model;

    2、We can get the proceure in the model browser;

    3、Right click the procedure name and create function import;

    4、In the popup dialog we can set function name and return type:

        Nothing return: chose none;

        returns single value: choose scalar option or choose entities;
        with special type : we can create the complex type first and mapping with it.

     

    I hope that would be help to you.

     

    Thanks to all the participators.

     


    If it's helpful for you, Please vote or mark. Thank you!

    David Peng [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, July 12, 2011 2:26 AM
    Moderator

All replies

  • Hi andybrum;

    The error message you are getting:

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

    From the error message it sounds like when you did the Function Import of the stored procedure you selected as its return type as type Person where it should be StudentGread. The reason you are getting the error is that the Person type has a column called PersonID but the data reader has no such column therefore they are incompatible.

    To correct the issue go to the edmx designer and in the Model Browser -> EntityContainer SchoolEntities -> Function Import select the stored procedure right click on it select properties in the Return Type click on the ... and in the Edit Function Import select StudentGread as the Entities.

     


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    Sunday, July 10, 2011 5:06 PM
  • Hi Andy,

     

    Welcome to the forum.

    It seems you function mapping with a invalid type.

    The steps to use store procedure in EF:

    1、Add the Store Procedure to the Entity Model Designer using Update Mode from database model;

    2、We can get the proceure in the model browser;

    3、Right click the procedure name and create function import;

    4、In the popup dialog we can set function name and return type:

        Nothing return: chose none;

        returns single value: choose scalar option or choose entities;
        with special type : we can create the complex type first and mapping with it.

     

    I hope that would be help to you.

     

    Thanks to all the participators.

     


    If it's helpful for you, Please vote or mark. Thank you!

    David Peng [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, July 12, 2011 2:26 AM
    Moderator