如何将Sql查询的结果映射到Net Core2中的对象上? [英] How to Map the results of Sql query onto Objects in Net Core2?
本文介绍了如何将Sql查询的结果映射到Net Core2中的对象上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何通过以下方法将SQL命令的结果映射到Net Core中的类对象中: SqlCommand()或FromSql()?有人可以为Net Core更新此答案吗,还是语法仍然相同?
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?
推荐答案
有了EntityFramework Core,您只需使用yourDbContextInstance.Set<T>().FromSql("your sql statement");
其中T
是您的课程.
但是,您的sql必须返回类的所有属性.
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.
这篇关于如何将Sql查询的结果映射到Net Core2中的对象上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文