The data reader is incompatible with the specified Entity Framework

前端 未结 3 1363
旧时难觅i
旧时难觅i 2020-12-18 20:10

I have a method that will return the bare min results from a sproc to fill a select menu. When I want the bare min results I pass bool getMin = true to the sproc, and when I

3条回答
  •  情歌与酒
    2020-12-18 20:27

    If you are inserting/deleting/updating (these are considered by EF as 'non-query'), and can be called by our code using

    MyDbContext.Database.ExecuteSqlCommand(insert into Table (Col1,Col2) values (1,2));
    

    But if are doing select query for a raw SQL statement, then use

    MyDbContext.DbSet.SqlQuery(select * from table_name).ToList();
    

    or

    MyDbContext.Database.SqlQuery(select * from table_name).ToList();
    

    ()

    The SqlQuery() function, in EF, for strange reasons, throw exception Insert/delete/update operation. (The exception thrown is "A member of the type, does not have a corresponding column in the data reader with the same name.") But it has actually performed operation if you open your Sql Management Studio and check for the entries.

    FYI http://www.entityframeworktutorial.net/EntityFramework4.3/raw-sql-query-in-entity-framework.aspx

提交回复
热议问题