I’m developing a report tool for my boss using ASP.NET MVC3 and the Entity Framework. I’m using a POCO model and DBContext to retrieve the data from our database and create the data layer. When I created some sample data it was simple: 2 tables with a small number of columns, and it worked liked a charm. Now I am trying to test my application in our test environment, which is where the issue has arisen.
The database that I am working with has 137 tables, but I only need data from two of the tables. I’ve emulated the two tables I need the data from and set up my application accordingly, but no dice. So my question is do I have to create a class for each table, even though my application is using only 2 of the tables from the database? Also, I have Read-Only privileges in this environment. Which should be fine because my application is simply selecting data, not manipulating it.
Update
The error I’m receiving is this:
EntityCommandExecutionException was unhandled by user code.
An error occured while executing the command definition.
Details: System.Data.SqlClient.SqlException: Invalid column name
The column name is the PK that I have for the other table I’m joining with.
Yes. You need to either create a class or generate classes for each table in your database. With entity framework the Database must match your DbContext classes. You’ll want to generate your classes as you’ve already created your database.
http://msdn.microsoft.com/en-us/data/jj206878.aspx