locked
The data reader is incompatible with the specified Model RRS feed

  • Question

  • User450763225 posted

    Hi, Guys, I got this below error when using EF6 and some sql queries. It should be very simple retrieve operation from the mapping. I attached the code causing this issue and the error message.

    private Service_PerformaceEntities db = new Service_PerformaceEntities();
    
            // GET: api/RTC_Resource_
            /* public IQueryable<RTC_Resource_> GetRTC_Resource_()
             {
                 return db.RTC_Resource_;
             }*/
            string sql = "select count(*) as Amount, [Owned By] as Owner from RTC_Resource$ group by[Owned By] order by Amount";
    
            public List<RTC_Resource_> GetRTC_Resource_()
            {
                return db.RTC_Resource_.SqlQuery(sql).ToList();
            }
    
    
    {"Message":"An error has occurred.","ExceptionMessage":"The data reader is incompatible with the specified 'Model.RTC_Resource_'. A member of the type, 'Id', does not have a corresponding column in the data reader with the same name.",



    Saturday, November 28, 2015 10:14 AM

Answers

  • User450763225 posted

    Hi, I have solved this problem, it is caused by different entity mapping. Thanks so much.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, November 30, 2015 2:11 PM

All replies

  • User753101303 posted

    Hi,

    And what is the class declaration for RTC_Resource_? Don"t you have an Id property which you don't read as told by the error message?

    Saturday, November 28, 2015 12:49 PM
  • User450763225 posted

    I did have ID column set up in the mapping. not sure why it said so.

    Actually, the problem is when I returned the whole result without sql query, it worked fine. so something wrong the returned dataset.

    Saturday, November 28, 2015 2:25 PM
  • User-271186128 posted

    Hi sdnd2000,

    According to your code and description, I suggest you could try to use the following code:

            public List<RTC_Resource_> GetRTC_Resource_()
            {
                List<RTC_Resource> list = (from cc in db.RTC_Resource_.SqlQuery(sql)
                                            select new RTC_Resource
                                            {
                                               property1 = cc.Owner,
                                               property2 = cc.Amount
                                            }).ToList(),
                //property1 and property2 are the fields in the RTC_Resource
    return list; }

    Best regards,
    Dillion

    Monday, November 30, 2015 2:50 AM
  • User450763225 posted

    Hi, I have solved this problem, it is caused by different entity mapping. Thanks so much.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, November 30, 2015 2:11 PM