System.InvalidCastException: 'The SqlParameterCollection only accepts non-null SqlParameter type objects, not SqlParameter objects.'
Fixed by changing using System.Data.SqlClient to using Microsoft.Data.SqlClient
https://github.com/aspnet/EntityFrameworkCore/issues/16812#issuecomment-516013245
This code worked after replacing
System.Data.SqlClient.SqlParameter
to
Microsoft.Data.SqlClient.SqlParameter
and
FirstOrDefault();
to
ToList();