问题
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