上下文不包含ExecuteStoreCommand的定义

编程入门 行业动态 更新时间:2024-10-27 09:46:29
本文介绍了上下文不包含ExecuteStoreCommand的定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试使用 context.ExecuteStoreCommand 对我的数据模型执行查询,但是我会收到错误消息:

I'm trying to execute a query against my data model with context.ExecuteStoreCommand but I keep getting the error message:

<object context> does not contain a definition for 'ExecuteStoreCommand' ...

我以前用过这个项目,我看不到我失踪了。我有项目引用EntityFramework,System.Data,System.Data.Entity。 MSDN文档说ObjectContext是System.Data.Object的一部分,但我不能直接引用,我不需要引用它以前使用它。我缺少什么?

I've used this before in an old project and I can't see what I'm missing. I've got project references to EntityFramework, System.Data, System.Data.Entity. The MSDN documentation says that ObjectContext is part of System.Data.Object but I can't reference that directly and I've not needed to reference it where I've used it before. What am I missing?

推荐答案

回答我自己的问题:

我最初使用ExecuteStoreCommand的代码已经在一个EF4项目中,其中代码生成策略被设置为Default,这导致正在创建一个ObjectContext。阅读这里,VS2012上的EF5似乎默认为数据模型创建了一个DbContext。

The code where I'd originally used ExecuteStoreCommand had been on an EF4 project where the Code Generation Strategy was set to "Default" which leads to an ObjectContext being created. Reading here it seems that EF5 on VS2012 creates a DbContext for the data model by default.

我发现了两种解决这个问题的方法。

I found two ways around this problem.

1 - 通过更改代码生成策略,从DbContext更改为ObjectContext。 此问题显示了如何执行此操作。可以使用< object context> .ExecuteStoreCommand()。

1 - Change from DbContext to ObjectContext by changing the code generation strategy. This question shows how to do it. <object context>.ExecuteStoreCommand() can then be used.

2 - 执行SQL命令DbContext,例如:

2 - Execute the SQL command against the DbContext, for example:

< db context> .Database.SqlQuery(typeof(myTable),SELECT * FROM myTable code>

<db context>.Database.SqlQuery(typeof(myTable), "SELECT * FROM myTable")

更多推荐

上下文不包含ExecuteStoreCommand的定义

本文发布于:2023-11-11 04:54:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1577431.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:上下文   不包含   定义   ExecuteStoreCommand

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!