What is advantages and usage for this

Posted by Jayakumars under C# on 4/17/2017 | Points: 10 | Views : 1089 | Status : [Member] [MVP] | Replies : 2
Hi

Why we use in mvc -> DbContext,DbSet but there no database but when i run application stored datas listed but My Question without database How it work in MVC?

No database but data stored and retrieve in mvc project using following class

how is it possible?

1.DbContext
2.DbSet<Employee>

Mark as Answer if its helpful to you

Kumaraspcode2009@gmail.com



Responses

Posted by: Sheonarayan on: 4/17/2017 [Administrator] HonoraryPlatinum | Points: 25

Up
0
Down
Instead of giving title of the question as "What is advantages and usage for this", it could have been "What is advantages and usage for DbContext" so that readers know by reading the title itself whether they can answer or not. The chances of reply with good and understandable title increases and you get quicker solution to your problem.

Here is the answer of your question ...

DbContext is nothing but an Entity Framework primary class object that has reference to the database connection string and objects (like tables, stored procedures, views etc.).

When you instantiate this class and call its method and properties, internally Entity Framework makes an SQL statement for you and execute against the database and you get the data in collections, or manipulate the data.

So assume the DbContext object as an your primary database access layer object that can manipulate all objects of your database.

When you add Entity Framework separately, you get an option to add tables, views, stored procedures etc.

In MVC, the Entity Framework base class is already created in the Models > IdentityModels.cs file and when you add a controller, a DbSet<model> property gets added so that you can access that entities data.

Read more about Entity Framework at http://techfunda.com/howto/asp-net-mvc/entity-framework.

Thanks

Regards,
Sheo Narayan
http://www.dotnetfunda.com

Jayakumars, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jayakumars on: 4/18/2017 [Member] [MVP] Bronze | Points: 25

Up
0
Down
Hi

I have added webconfig file also connection string . But after save records i am open my database select the particular table but no records is there but in my mvc application records listed how is it possible?


Dbset automatically created whether application runtime?

i do know can you explain more.

if you have crud operations EF -> code first in techfunda please share url plz

Mark as Answer if its helpful to you

Kumaraspcode2009@gmail.com

Jayakumars, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response