question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Expression of type 'System.Object' cannot be used for parameter of type 'Microsoft.EntityFrameworkCore.Metadata.IEntityType'

See original GitHub issue

Since 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:closed
  • Created 6 years ago
  • Reactions:5
  • Comments:20 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
maumarcommented, Jan 23, 2020

@paillave ideally, file a new issue with the info and reference this one.

1reaction
maumarcommented, Jan 23, 2020

@paillave can you provide full code listing? (i.e. entities and dbcontext)

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found