Entity framework terms used with asp net mvc app

Ok, I tried some entity framework with ASP NET MVC and got it working. Hurray!

This is the code that I managed to write:

        public ActionResult Index([Bind(Prefix="id")] int patientId = 0)
        {
            Patient patient = db.Patients.Find(patientId);
            if (patient == null)
            {
                return HttpNotFound();   
            }

            return View(patient);
        }

When somebody types out the URL, this action-method queries the localdb in my Visual studio and I get the patient, display it in a view.

Now, its the time to go for some basics.

While everything above works great, I still have some difficulty to get used to some MVC terms that MVC guru's use out there in the real world.

  1. What does the term Entity exactly used for? Is it an representation of the model class?

  2. The term Context in DbContext class. How will you define that ?

  3. In the above code, the visual studio 2012 on mouse over of Find method displays its signature as "Patient DbSet.Find(params object[] keyValues).

    The method description available there also says "Finds an entity with the given primary key values. If an entity with the given primary key values exists in the context, then it is returned immediately without making a request to store."

  4. What is the store refer to in the above description?

  5. The Find method signature contains the keyword params. So, there are possibilities to pass multiple objects to it. Any examples wheremultiple primary keys are passed ?

Upvotes: 2

Views: 257

Answers (2)

Andre Pena
Andre Pena

Reputation: 59396

1 What does the term Entity exactly used for? Is it an representation of the model class?

Entity usually refers to a class that has a one-to-one relationship with the database. It's your database model class. There are several types of models: view models, data transfer models and actual database models (commonly referred to as entity)

2 - The term Context in DbContext class. How will you define that ?

The context represents your database. Every table you have there that is mapped will have it's own DbSet<T> in the context through which you can query it.

3/4 - In the above code, the visual studio 2012 on mouse over of Find method displays its signature as "Patient DbSet.Find(params object[] keyValues).

Store means the actual database. What the Find documentation is trying to say is that , if the object corresponding to the passed key already exists in the ObjectStateManager, that is, if it has been retrieved already by a previous query, Entity Framework is not going to round trip to the server to get this same object again.

The Find method signature contains the keyword params. So, there are possibilities to pass multiple objects to it. Any examples where multiple primary keys are passed ?

You would use multiple parameters when you have a composite primary key.

Upvotes: 3

CodeCaster
CodeCaster

Reputation: 151674

What does the term Entity exactly used for? Is it an representation of the model class?

No, an entity is a database entity. It's generally frowned upon to use database models as viewmodels.

The term Context in DbContext class. How will you define that ?

A database context. A collection of tables.

What is the store refer to in the above description?

The database.

The Find method signature contains the keyword params. So, there are possibilities to pass multiple objects to it. Any examples wheremultiple primary keys are passed ?

It says:

Finds an entity with the given primary key values

An entity can have a composite primary key.


Why don't you pick up a good book on MVC or Entity Framework to get a better understanding of the subject? :-) Please try to show more research effort.

Upvotes: 3

Related Questions