使用 Entity SQL 查询概念模型
我想我在某处读到,您实际上可以使用基于字符串的查询来使用实体 Sql 查询概念模型,如下所示:
class DBSetTest<T> : List<T>
{
DBEntities db = new DBEntities();
public DBSetTest()
{
ObjectQuery<T> test = new ObjectQuery<T>("SELECT Name FROM Sessions WHERE Name = 'sean'", db);
foreach (var v in test)
{
this.Add(v);
}
}
}
其中“Sessions”是我使用“DefiningQuery”定义的自定义实体类型。否则我会使用正常的 linq 语法来查询它。 Entity SQL 只查询存储还是可以像 LINQ-to-Entities 一样查询我的概念模型?如果是这样,不确定我的语法是否正确,因为它可能不是 sql 语法。我的目标是在这里创建一种自定义通用列表,我可以在其中针对我的概念模型编写动态查询。
我收到以下错误:
无法在当前范围或上下文中解析“名称”。确保所有引用的变量都在范围内,加载所需的架构,并且正确引用命名空间。靠近简单标识符,第 1 行,第 43 列。
Thought I read somewhere that you in fact can query your conceptual model with Entity Sql, using string based queries as such:
class DBSetTest<T> : List<T>
{
DBEntities db = new DBEntities();
public DBSetTest()
{
ObjectQuery<T> test = new ObjectQuery<T>("SELECT Name FROM Sessions WHERE Name = 'sean'", db);
foreach (var v in test)
{
this.Add(v);
}
}
}
Where 'Sessions' is a custom Entity Type I defined with a 'DefiningQuery'. I would otherwise query it with normal linq syntax. Does Entity SQL only query the store or can it query my conceptual model just like LINQ-to-Entities does? If so not sure I have the right syntax, since it probably isn't sql syntax. My goal is to create a sort of custom generic list here, where I can write dynamic queries against my conceptual model.
I get the following error:
'Name' could not be resolved in the current scope or context. Make sure that all referenced variables are in scope, that required schemas are loaded, and that namespaces are referenced correctly. Near simple identifier, line 1, column 43.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为,这不是有效的 Entity SQL 语法,
也许你必须添加一些像这样的关键字:
I think, It is not valid Entity SQL sintax,
probably you must add some keyword like this :
您收到的错误表明您必须将其放入。在名称之前,如下所示:
The error you get says that you must put it. before Name, like this: