How to Map the results of Sql query onto Objects in Net Core2?

戏子无情 提交于 2019-12-25 03:22:47

问题


How can I map the results of a SQL command into a class object in Net Core, with SqlCommand() or FromSql()? Can someone update this answer for Net Core, or is the syntax still the same?

How can I map the results of a sql query onto objects?


回答1:


With EntityFramework Core, you simply use yourDbContextInstance.Set<T>().FromSql("your sql statement"); Where T is your class. However, your sql MUST return all the properties on your class.

See documentation for more details on this.



来源:https://stackoverflow.com/questions/53586872/how-to-map-the-results-of-sql-query-onto-objects-in-net-core2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!