Link to home
Start Free TrialLog in
Avatar of dionisio_79
dionisio_79

asked on

Entity Framework Code First NullReferenceException

Hi Experts,
I'm using Entity Framework Code First, I've an entity Articolo and ZefiroContext : DbContext which contains the following declaration:

public DbSet<Articolo> Articoli { get; set; }

When I run the following code:

var a = new ZefiroContext().Articoli;
List<Articolo> r;
if (a != null)
    r = a.ToList();
else
    r = new List<Articolo>();

I get a NullReferenceException at line r = a.ToList();.
I have no data in table Articoloes in my database so I expect my variable r to point to an empty List<Articolo>.
ASKER CERTIFIED SOLUTION
Avatar of dionisio_79
dionisio_79

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dionisio_79
dionisio_79

ASKER

There were underlaying problems with my Sql Server instance