I am developing a simple project using Entity Framework, it used to run and load all my database before I reinstall a new copy of windows.

I was using Windows 10; SQL Server 2016; Entity Framework 6.1.3 and target .NET 4.5.2, and Visual Studio 2015.

I re-installed a fresh copy of Windows 10 and everything else.

I made a data connection to my .mdf file and I can read the database in my Visual Studio Server Explorer and verify that my tables are populated with all the rows.

When I run the project I have this error:

"An exception of type 'System.NullReferenceException' occurred in myApp.exe but was not handled in user code"

This is happening because it is reading a list that should be populated from one of my entity attributes

My question is: when I create my DbContext instance, why does it not load any of the entities and their attributes?

Any idea?

EDIT: This is the connection string

" Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename="F:\Files\Development\C#\Visual Studio 2015\Projects\NurseOfficeApp\NurseOfficeApp\DB\NurseOfficeApp.NurseOfficeContext.mdf";Integrated Security=True;Connect Timeout=30"

this is where I have the problem

private void FrmDesignAgency_Load(object sender, EventArgs e)
     _context = new NurseOfficeContext();
     var mylist = _context.Set<Agency>().ToList();// mylist.count = 0

mylist.count shouldn't be 0

6/10/2017 8:42:32 PM

Popular Answer

You can follow the instructions on the following URL:

It will help you to setup your first EF application

6/9/2017 1:33:06 AM

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow