0

First time working with entity framework, I've been testing with an in memory database which has been working fine but wanted to start working on a persistent database using sqlite.

I've got the model and context created, when I run Add-Migration in the Package Manager Console it seems to work fine but when I then run the Update-Database function I always get a 'Object reference not set to an instance of an object' error but I can't work out why, any help really appreciated, been searching around for a while and can't see anything.

Screenshot of the reported error

I've got four model classes and the context class so not sure I can include all the code snippets here but happy to if folk think it's needed to get anywhere.

Thanks.

Hobospy
  • 41
  • 5
  • Does this answer your question? [What is a NullReferenceException, and how do I fix it?](https://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) – 41686d6564 Apr 07 '20 at 13:32
  • Are you passing in the migration name to [Update-Database](https://docs.microsoft.com/en-us/ef/core/miscellaneous/cli/powershell#update-database)? – rainydevbs Apr 07 '20 at 13:33
  • No, I am passing in the Context name, is it supposed to be the migration name created by the Add-Migration call? – Hobospy Apr 07 '20 at 21:07

1 Answers1

1

OK so I found out what the issue was. The "Object reference not set to an instance of an object" in this case was due to the fact that I didn't have a reference to Microsoft.EntityFrameworkCore.Sqlite. I did have a reference to Microsoft.EntityFrameworkCore.Sqlite.Core which is what allowed the project to build OK but apparently this is required for the Update-Database call.

Also for anyone else needing to take a step back and just confirm they aren't going crazy, this is a good website describing what is needed. I used this just to confirm everything worked OK and I hadn't missed something (which I obviously had).

TL:DR - Make sure you have a reference to Microsoft.EntityFrameworkCore.Sqlite

Hobospy
  • 41
  • 5