The steps that I follow ...
Add a new ADO.NET entity data model> Create from database> Install a new connection string in adventureworks db> Next> Select the "DatabaseLog" table> Done. Verify that the DatabaseLog is displayed in the edmx view.
Right Click Controller> Add Controller
Template
Controller with read / write actions and views using Entity
Model class
AdventureWorksDWEntities
Context
New Data Context> Accept Default Name
View
Razor
Click Add.
To produce an error:
"Failed to get metadata for" DatabaseDocumentor.models.AdventureWorksDWEntities ".
System.Data.Edm.EdmEntityeType: EntityType "AdventureWorksDWEntities" does not have a specific key. Define a key for this entity type.
System.Data.Edm.EdmEntitySet: EntityType: EntitySet "AdventureWorksDWEntities" is based on the type "AdventureWorksDWEntities", which does not have specific keys.
I tried again using AdventureWorks (not AdventureWorksDW), and this time it worked. But I still do not understand what to choose when creating the controller. I have 3 options:
Template
Here I chose Controller with read / write actions and views using Entity. This is easy enough to understand. I want my tables to be created for me, so I select this option.
Model
This is what I want to simulate. In this case, I want to simulate the Department table. Therefore, I choose the Department.
Context
This is completely fuzzy for me. I selected * Name * Entities. This value is in the web.config connection string area. Why do I need to select a connection string as context? I only know the context as "the object that I use to access my entities" in C #. So, it's hard for me to imagine here. Should I always select a connection string for context?
source share