【发布时间】:2015-11-10 23:03:32
【问题描述】:
我正在使用带有 Framework 4.0 的 Visual Studio 2010 Express,如果我是正确的,它带有 Entity Framework 4。
我的 ObjectContext 定义为:
public partial class CreaturesEntities : global::System.Data.Objects.ObjectContext
我尝试使用 ExecuteStoreQuery :
using System.Data.Objects;
using System.Data.Entity;
[...]
context = new CreaturesEntities();
string query = "select type, min(value) value from saving_throw where ";
string conditions = "(classe_id=" + classe_id + " and level=" + level1 + ")";
if (classe.subclass1_id != null)
conditions += " or (classe_id=" + classe.subclass1_id + " and level=" + level1 + ")";
if (classe.subclass2_id != null)
conditions += " or (classe_id=" + classe.subclass2_id + " and level=" + level2 + ")";
if (classe.subclass3_id != null)
conditions += " or (classe_id=" + classe.subclass3_id + " and level=" + level3 + ")";
query = query + conditions + " group by type";
var q = context.ExecuteStoreQuery<SimpleNumber>(query);
// SimpleNumber is a class with an int property, I suppose ExecuteStoreQuery<Integer> wouldn't work?
当我输入“context.”时,我在上下文菜单中找不到 ExecuteStoreQuery,这意味着无论出于何种原因它都不可用。 我在 ObjectContext 中找不到任何有关缺失方法的信息。 这是否意味着 Visual Studio 2010 Express 不包含 Entity Framework 4 ?因为标准版可以,而快递版使用旧版本会很奇怪。
当然,我可以使用经典的 DataReader,但 ExecuteStoreQuery 要好得多。
有什么想法吗?
编辑:我将查询更改为真实查询以解释为什么 ExecuteStoreQuery 有时对于复杂查询更容易(至少对于 LINQ To Entities 的初学者而言)
【问题讨论】:
-
我知道在 Linq2SQL 中称为
ExecuteQuery。你确定你的名字是正确的? -
ExecuteStoreQuery 在我的实体框架项目中可用。我刚刚检查过了。但我从未使用过它。我使用 linq 进行所有查询。