Value cannot be null. Parameter name: source
Somewhere inside the DbContext is a value that is IEnumerable
and is queried with Any()
(or Where()
or Select()
or any other LINQ-method), but this value is null
.
Find out if you put a query together (somewhere outside your example code) where you are using a LINQ-method, or that you used an IEnumerable
as a parameter which is NULL.
I just got this exact error in .Net Core 2.2 Entity Framework because I didn't have the set;
in my DbContext
like so:
public DbSet<Account> Account { get; }
changed to:
public DbSet<Account> Account { get; set;}
However, it didn't show the exception until I tried to use a linq query with Where()
and Select()
as others had mentioned above.
I was trying to set the DbSet
as read only. I'll keep trying...
I had this one a while back, and the answer isn't necessarily what you'd expect. This error message often crops up when your connection string is wrong.
At a guess, you'll need something like this:
<connectionStrings>
<add name="hublisherEntities" connectionString="Data Source=localhost;Initial Catalog=hublisher;Integrated Security=True;" providerName="System.Data.SqlClient" />
</connectionStrings>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="Data Source=localhost;Initial Catalog=hublisher;Integrated Security=True" />
</parameters>
</defaultConnectionFactory>
</entityFramework>
What's happening is that it's looking for a data source in the wrong place; Entity Framework specifies it slightly differently. If you post your connection string and EF config then we can check.