I'm using .NET 6 and Entity Framework Core 6 (6.0.2) in an ASP.NET Core Web API project.
Assuming I have:
public class MyModel
{
public Guid Id { get; set; }
public string MyData { get; set; }
//etc...
}
public class ApplicationDbContext : DbContext
{
public DbSet<MyModel> MyModels { get; set; }
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> opt) : base(opt)
{
}
}
If I'm in a generic function with the object MyModel myModel
, then how can I know if this instance of MyModel
is an entity tracked by Entity Framework Core?
I'm looking for a function like:
ApplicationDbContext context = ...
MyModel myModel = ...
//ecc...
bool result = context.IsOneOfMyEntity(myModel);