[{"data":1,"prerenderedAt":87},["ShallowReactive",2],{"/2025/09/28-entity-framework-(ef)-6-database.sqlquery-mapping":3},{"id":4,"title":5,"body":6,"date":78,"description":75,"extension":79,"meta":80,"navigation":81,"path":82,"robots":83,"seo":84,"stem":85,"__hash__":86},"posts/2025/09/28 Entity-Framework-(EF)-6-Database.SqlQuery-mapping.md","28 Entity Framework (EF) 6 DatabaseSqlQuery Mapping",{"type":7,"value":8,"toc":74},"minimark",[9,18,25,28,31,33,59,61],[10,11,13],"post-title",{":date":12},"date",[14,15,17],"h1",{"id":16},"entity-framework-ef-6-databasesqlquery-mapping","Entity Framework (EF) 6 Database.SqlQuery Mapping",[19,20,21],"notes",{},[22,23,24],"p",{},"This is a repost from my old blog. First posted in 8/27/2018.",[26,27],"br",{},[22,29,30],{},"I bumped into a problem with mapping results from manually crafted sql query to object using EF. Somehow, it doesn't seem to recognize the column attribute. And I found out that it really doesn't and they don't plan to enhance EF 6, although there seems to have the option in EF Core to do the mapping.",[26,32],{},[22,34,35,36,40,41,44,45,53,54,58],{},"To illustrate my problem better, suppose my database column name is ",[37,38,39],"strong",{},"pk"," and would like to map it to ",[37,42,43],{},"ID"," property. Usually, using ",[46,47,52],"code",{"className":48},[49,50,51],"bg-gray-200","p-2","rounded","[Column(\"pk\")]"," will solve the mapping, however, it doesn't work if the query was executed via ",[46,55,57],{"className":56},[49,50,51],"dbContext.Database.SqlQuery(\"SELECT pk FROM TableName\")",".",[26,60],{},[22,62,63,64,66,67,69,70,58],{},"So I have to either change the ",[37,65,43],{}," property to ",[37,68,39],{}," or the one that I preferred is to change the query to ",[46,71,73],{"className":72},[49,50,51],"dbContext.Database.SqlQuery(\"SELECT pk AS ID FROM TableName\")",{"title":75,"searchDepth":76,"depth":76,"links":77},"",2,[],"2025-09-28T00:00:00.000Z","md",{},true,"/2025/09/28-entity-framework-(ef)-6-database.sqlquery-mapping",null,{"title":5,"description":75},"2025/09/28 Entity-Framework-(EF)-6-Database.SqlQuery-mapping","Y_nK3BPNfNFoTIhJdRBJIi7s7kcZ5xT36E5XM6_a6Jc",1785167453035]