I am using EntityFramework in my ASP.Net MVC project. The problem is that I don't get any data from the database at all. My database is localDB, and the next connection string I use is
<connectionStrings> <add name="PortfolioDBContext" connectionString="Data Source=(localdb)\v11.0;Initial Catalog=NoobMVC;Integrated Security=True" providerName="System.Data.SqlClient"/> </connectionStrings>
Following is my implementation of the Db context -
public class PortfolioDBContext : DbContext { public PortfolioDBContext() { Debug.Write("Noob CONNNNN "+Database.Connection.ConnectionString); } public DbSet<Product> Portfolio { get; set; } }
And this is what my controller looks like -
public class HomeController : Controller {
I'm not sure what else I need to do to get the data in DbSet. Am I missing any step here or is there a way to debug the exact problem? I've already searched for SO, and it looks like I'm the only one stuck here.
Update:
I have already tried sending various ways to send data to a view. The main problem is context, not presentation. I do not receive any data in the context, therefore, how I send this data for viewing does not matter.
Update 2: - When you tried to log requests using the ChrFin method, I received the following logs -
Opened connection at 16-10-2014 06:32:07 PM +05:30 SELECT Count(*) FROM INFORMATION_SCHEMA.TABLES AS t WHERE t.TABLE_SCHEMA + '.' + t.TABLE_NAME IN ('dbo.Products') OR t.TABLE_NAME = 'EdmMetadata' -- Executing at 16-10-2014 06:32:08 PM +05:30 -- Completed in 21 ms with result: 1 Closed connection at 16-10-2014 06:32:08 PM +05:30 Opened connection at 16-10-2014 06:32:08 PM +05:30 SELECT [GroupBy1].[A1] AS [C1] FROM ( SELECT COUNT(1) AS [A1] FROM [dbo].[__MigrationHistory] AS [Extent1] WHERE [Extent1].[ContextKey] = @p__linq__0 ) AS [GroupBy1] -- p__linq__0: 'Noob_MVC.Models.PortfolioDBContext' (Type = String, Size = 4000) -- Executing at 16-10-2014 06:32:08 PM +05:30 -- Completed in 21 ms with result: SqlDataReader Closed connection at 16-10-2014 06:32:08 PM +05:30 Opened connection at 16-10-2014 06:32:08 PM +05:30 SELECT TOP (1) [Project1].[C1] AS [C1], [Project1].[MigrationId] AS [MigrationId], [Project1].[Model] AS [Model], [Project1].[ProductVersion] AS [ProductVersion] FROM ( SELECT [Extent1].[MigrationId] AS [MigrationId], [Extent1].[Model] AS [Model], [Extent1].[ProductVersion] AS [ProductVersion], 1 AS [C1] FROM [dbo].[__MigrationHistory] AS [Extent1] WHERE [Extent1].[ContextKey] = @p__linq__0 ) AS [Project1] ORDER BY [Project1].[MigrationId] DESC -- p__linq__0: 'Noob_MVC.Models.PortfolioDBContext' (Type = String, Size = 4000) -- Executing at 16-10-2014 06:32:08 PM +05:30 -- Completed in 17 ms with result: SqlDataReader Closed connection at 16-10-2014 06:32:08 PM +05:30 Opened connection at 16-10-2014 06:32:08 PM +05:30 SELECT [GroupBy1].[A1] AS [C1] FROM ( SELECT COUNT(1) AS [A1] FROM [dbo].[Products] AS [Extent1] ) AS [GroupBy1] -- Executing at 16-10-2014 06:32:08 PM +05:30 -- Completed in 10 ms with result: SqlDataReader Closed connection at 16-10-2014 06:32:08 PM +05:30 Noob context size 0Opened connection at 16-10-2014 06:32:08 PM +05:30 'iisexpress.exe' (CLR v4.0.30319: /LM/W3SVC/21/ROOT-1-130579381242638924): Loaded 'EntityFrameworkDynamicProxies-Noob MVC'. SELECT [Extent1].[Id] AS [Id], [Extent1].[Name] AS [Name], [Extent1].[Description] AS [Description], [Extent1].[Link] AS [Link], [Extent1].[SmallImageLink] AS [SmallImageLink], [Extent1].[LargeImageLink] AS [LargeImageLink] FROM [dbo].[Products] AS [Extent1] -- Executing at 16-10-2014 06:32:08 PM +05:30 -- Completed in 11 ms with result: SqlDataReader Closed connection at 16-10-2014 06:32:08 PM +05:30
I'm sure something is awkward here. The name of the table is Portfolio, not Products.
Update 3: -
The issue was finally resolved. See below for more details.