-1

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 !

  • Good that you are trying to learn EF but you have several larger issues probably because you are all over the place in trying to learn this. I recommend you take a step back and follow a focused tutorial, once you understand the core concepts and how to apply them THEN go back and try to apply what you have learned to your specific problem that you want to solve. To get you started here is a tutorial posted on the official Microsoft EF site: https://www.asp.net/mvc/overview/getting-started/getting-started-with-ef-using-mvc/creating-an-entity-framework-data-model-for-an-asp-net-mvc-application – Igor Oct 27 '15 at 15:35

1 Answers1

0

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.

DrewJordan
  • 5,266
  • 1
  • 25
  • 39