using (var context = new MyContext())
{
var customers = context.Customers.ToList();
}
Is correct? Visual studio doesn't accept it and appears red line under it!
If you have red squiggles, I'm pretty certain that you have simply copied and pasted the code as-is and expected it to work. Have you actually created a DbContext called "MyContext" that has a DbSet called "Customers"? If not, the code will never work for you.
That site is not a tutorial site. It's just a collection of snippets of code. You should go through a step-by-step tutorial for beginners like mgebhard suggested. You also need to review the basics of C#, I suggest.
It's close from code that works. For now it seems they don't show or shown earlier how to declare thre MyContext class My guess is that this class is not defined correctly (or at all?l). As pointed earlier it would be easier to guide you knowing which error
message you have. We don't even know if this is a compile time or runtime error.
Edit: see for example
https://entityframeworkcore.com/approach-code-first if you need guidance about the MyContext class though it seems they switched at some point from Order/OrderDetail to Customer which perhaps doesn't help you to get something up and running.
Member
21 Points
246 Posts
Do you think this tutorial is wrong or outdated
Jan 15, 2021 08:54 PM|SaeedP|LINK
Hello,
I'm learning the Entity framework core and encountered in this tutorial:
You can see the page here:
https://entityframeworkcore.com/querying-data-basic-query
And in there comes:
Let's say we have a simple model which contains three entities.
Load All data
The following example loads all the data from
Customers
table.This code isn't working. Is this wrong or outdated?
thanks,
All-Star
53001 Points
23593 Posts
Re: Do you think this tutorial is wrong or outdated
Jan 15, 2021 09:11 PM|mgebhard|LINK
The answer depends on what you mean by "isn't working".
Member
21 Points
246 Posts
Re: Do you think this tutorial is wrong or outdated
Jan 15, 2021 09:55 PM|SaeedP|LINK
I mean this part:
Is correct? Visual studio doesn't accept it and appears red line under it!
All-Star
53001 Points
23593 Posts
Re: Do you think this tutorial is wrong or outdated
Jan 16, 2021 02:05 AM|mgebhard|LINK
There is nothing technically wrong with the code. The example assumes a fundamental understanding of EF Core.
I recommend the official documentation for learning EF Core.
https://docs.microsoft.com/en-us/ef/core/get-started/overview/first-app?tabs=netcore-cli
All-Star
194434 Points
28074 Posts
Moderator
Re: Do you think this tutorial is wrong or outdated
Jan 16, 2021 09:13 AM|Mikesdotnetting|LINK
That site is not a tutorial site. It's just a collection of snippets of code. You should go through a step-by-step tutorial for beginners like mgebhard suggested. You also need to review the basics of C#, I suggest.
Member
21 Points
246 Posts
Re: Do you think this tutorial is wrong or outdated
Jan 17, 2021 05:15 PM|SaeedP|LINK
But the site claims that was a tutorial nat snippet. Anyway, there is another site for the entity-framework core.
I think that's from you, It is a cool site. I learned many things from that.
All-Star
194434 Points
28074 Posts
Moderator
Re: Do you think this tutorial is wrong or outdated
Jan 17, 2021 05:52 PM|Mikesdotnetting|LINK
I have got one at learnentityframeworkcore.com. It has got a couple of step-by-step walkthroughs, but they probably need updating.
https://www.learnentityframeworkcore.com/walkthroughs
All-Star
48500 Points
18071 Posts
Re: Do you think this tutorial is wrong or outdated
Jan 17, 2021 06:49 PM|PatriceSc|LINK
Hi,
It's close from code that works. For now it seems they don't show or shown earlier how to declare thre MyContext class My guess is that this class is not defined correctly (or at all?l). As pointed earlier it would be easier to guide you knowing which error message you have. We don't even know if this is a compile time or runtime error.
Edit: see for example https://entityframeworkcore.com/approach-code-first if you need guidance about the MyContext class though it seems they switched at some point from Order/OrderDetail to Customer which perhaps doesn't help you to get something up and running.