简体   繁体   English

实体 SQL 问题?

[英]Entity SQL problems?

I'm learning about Entity SQL but I'm having some problem about how to code, I found on the Internet that most of the code they're all written like this.我正在学习 Entity SQL,但是我在如何编码方面遇到了一些问题,我在 Internet 上发现大多数代码都是这样编写的。

ObjectQuery<EntitiesName> example = new ObjectQuery<EntitiesName>(query);
ObjectQuery<EntitiesName> example2 = context.CreateQuery<EntitiesName>(query);

So that mine problem, I'm using Entity Framwork 6.1.3, Visual 2013 and SQL 2014. I try to write like that but it won't use.所以我的问题,我使用 Entity Framwork 6.1.3、Visual 2013 和 SQL 2014。我试着这样写,但它不会使用。 Then i found on the Internet this type of code.然后我在网上找到了这种类型的代码。

ObjectQuery<EntitiesName> exm = ((IOContextAdapter)context).ObjectContext.CreateQuery<EntitiesName>(query);

I don't understand because the different of EF version or my visual, sql don't support that.我不明白,因为 EF 版本或我的视觉不同,sql 不支持。 And another problem is I'm writing on Winform C# but when I type :另一个问题是我在 Winform C# 上写,但是当我输入:

dataGridView.DataSource = context.ToList();

It says that System.data.entity.core.objects.objectquery does not contain definition for ToList().它说 System.data.entity.core.objects.objectquery 不包含 ToList() 的定义。

Click here to see the picture of problems点击这里查看问题图片

Hope can get the answer soon, thank you !希望能尽快得到答复,谢谢!

I think you're missing the basic use case of EF.我认为您缺少 EF 的基本用例。 For most use cases, you don't have to write SQL;对于大多数用例,您不必编写 SQL; that's the whole point.这就是重点。

It's kind of impossible to tell what you're doing without seeing your actual code, but it looks like you're on the right track.不看实际代码就不可能知道你在做什么,但看起来你走在正确的轨道上。 Try context.EntitiesName.ToList() where EntitiesName is the actual name of one of your classes.尝试context.EntitiesName.ToList()其中EntitiesName是您的类之一的实际名称。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM