简体   繁体   中英

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.

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. 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. And another problem is I'm writing on Winform C# but when I type :

dataGridView.DataSource = context.ToList();

It says that System.data.entity.core.objects.objectquery does not contain definition for 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. For most use cases, you don't have to write 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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