Tuesday, February 25, 2020

The JSON value could not be converted to System.Collections.Generic.IEnumerable`1[Newtonsoft.Json.Linq.JToken]

If you are getting the following error in your .Net Core Project
"The JSON value could not be converted to System.Collections.Generic.IEnumerable`1[Newtonsoft.Json.Linq.JToken]"
Then you have to install the "Microsoft.AspNetCore.Mvc.NewtonsoftJson" Nuget package.

Afterwards, in the startup class, update Startup.ConfigureServices to call AddNewtonsoftJson.
Example:

public void ConfigureServices(IServiceCollection services)
{
services.AddControllersWithViews().AddNewtonsoftJson();
  }

Friday, February 7, 2020

Entitty Framework Core - Migrations

To migrate through the package manager console download the Nuget "Microsoft.EntityFrameworkCore.Tools"

The Enable-migration is deprecated in Core, so no need of this command as the migrations are enabled by default.


Adding a migration
Example : Add-Migration MyFirstMigration

Update the database
update-database

To get a SQL script containing all migration snapshots use the below command:
 Script-Migration

For more help on EF Core migrations type in the below command in Package manage console
 Get-Help entityframework