Expression of type 'System.Object' cannot be used for parameter of type 'Microsoft.EntityFrameworkCore.Metadata.IEntityType'
See original GitHub issueSince updating to v2 I now get the following exception from one of my unit tests:
System.ArgumentException : Expression of type 'System.Object' cannot be used for parameter of type 'Microsoft.EntityFrameworkCore.Metadata.IEntityType' of method 'Void StartTracking(System.Object, Microsoft.EntityFrameworkCore.Metadata.IEntityType)'
Parameter name: arg1
In order to get the test to pass I have had to change:
var projects = this.context.Projects
.Include(p => p.Windfarm)
.Include(p => p.Turbines)
.Where(p => p.Windfarm.ClientId == clientId && p.IsActive)
.GroupBy(g => g.WindfarmId)
.Select(s => s.OrderByDescending(o => o.DateStarted).FirstOrDefault())
.ToList();
to the following:
var activeProjects = this.context.Projects
.Include(p => p.Windfarm)
.Include(p => p.Turbines)
.Where(p => p.Windfarm.ClientId == clientId && p.IsActive)
.GroupBy(g => g.WindfarmId).ToList();
var projects = activeProjects.Select(s => s.OrderByDescending(o => o.DateStarted).FirstOrDefault())
.ToList();
Issue Analytics
- State:
- Created 6 years ago
- Reactions:5
- Comments:20 (12 by maintainers)
Top Results From Across the Web
Expression of type 'System.Int32' cannot be used for ...
EDIT. Found the solution in this question. You need to convert the expression to Object before calling the Equals(object) method:
Read more >CoreStrings Class
Obsolete. The entity type '{entityType}' cannot be added to the model because an entity type with a defining navigation with the same name...
Read more >DbSet<TEntity> Class (Microsoft.EntityFrameworkCore)
A DbSet<TEntity> can be used to query and save instances of TEntity. ... The type of entity being operated on by this set....
Read more >IEntityType Interface
Returns the entity type mapping for a particular table-like store object. This method is typically used by database providers (and other extensions). It...
Read more >Object reference not set to an instance of an object. Entity ...
I have the above error showing in Visual Studio 2019. The project is built on a Asp.Net Core 3.1 and EF Core 3.1,...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@paillave ideally, file a new issue with the info and reference this one.
@paillave can you provide full code listing? (i.e. entities and dbcontext)