EF6 stored procedure with no results

南楼画角 提交于 2019-12-12 13:53:11

问题


My environment is VS 2012, C#, EF6 and SQL Server 2008 R2.

I want to execute a stored procedure to delete records with no return value using the pattern:

dataContext.Database.SqlQuery<return type>("name", parameter)

If there are no results returned e.g. with NO COUNT ON what should I set as the return type? Seems that it should be simple but I cannot find an answer anywhere.

I tried dataContext.Database.SqlQuery("name", parameter) but that returns a compile error: The best overloaded method match for 'System.Data.Entity.Database.SqlQuery(System.Type, string, params object[])' has some invalid arguments


回答1:


Use ExecuteSqlCommand instead of SqlQuery if you don't need to query some data:

dataContext.Database.ExecuteSqlCommand("name", parameter)


来源:https://stackoverflow.com/questions/21043585/ef6-stored-procedure-with-no-results

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