如何使用 LINQ to Entities 运行 T-SQL 查询?
我想执行一些 T-SQL。我想使用现有的 L2E 连接配置,我不想将新的 SqlClient 提供程序连接配置添加到我的 .config 文件中。我该怎么做? ObjectContext 似乎只有从数据映射架构中返回类结果的方法。
我尝试过执行 ObjectContext.Connection.CreateCommand 方法,然后将我的 T-SQL 指定为命令文本,但它失败并显示类似“无法理解您在查询中谈论的实体”之类的消息。
I want to execute some T-SQL. I want to use existing L2E connection configurations, I don't want to add a new SqlClient provider connection configuration to my .config file. How do I do that? ObjectContext seems to have only methods that return results with classes from data mapping schema.
I've tried doing ObjectContext.Connection.CreateCommand method, then specifying my T-SQL as the command text, but it failed with a message that is something like "could not understand what entities you are talking about in your query".
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
ExecuteStoreQuery()
。另请参阅如何:直接针对数据源执行命令You can use
ExecuteStoreQuery()
. Also see How to: Directly Execute Commands Against the Data Source