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.

Add resource removal to ChangeTracking

See original GitHub issue

I suggest adding such a pattern to EF Core to remove unnecessary resources from ChangeTracker

using System;
using Microsoft.EntityFrameworkCore;

//Example Use
var myDb = new MyDbContext();
using var info = new Info();
myDb.AddInfo(info);
myDb.SaveChanges();

class MyDbContext:DbContext 
{
    public DbSet<Info> information { set; get; }
    public void AddInfo(Info info)
    {
        if(info is IChangeTrackingDispose<Info> change)
        {
            change.SetDbSet(information);
        }
        information.Add(info);
    }
}
public class Info : IChangeTrackingDispose<Info>
{
    public int Id {set;get;}
    public DbSet<Info> _dbSet { set; get; }

    public void Dispose()
    {
        (this as IChangeTrackingDispose<Info>).Close();
    }
}

interface IChangeTrackingDispose<T>:IDisposable where T : class
{

    DbSet<T> _dbSet { set; get; }
    public void SetDbSet(DbSet<T> dbSet)
    {
        _dbSet = dbSet;
    }
    private void RemoveFromChangeTraking()
    {
        ///The logic for removing this instance from Change Tracking
    }
    public void Close()
    {
        RemoveFromChangeTraking();
    }

}

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:11
  • Comments:50 (20 by maintainers)

github_iconTop GitHub Comments

2reactions
rojicommented, Sep 17, 2022

I’ve done my best to describe EF best practices, and how the product was designed to be used - the conversation seems to be going in circles at this point. I think that between the above and the EF documentation you should have all the information in order to write an EF program according to our recommended guidelines.

1reaction
Mr0Ncommented, Sep 17, 2022

@Mr0N there really are no memory leaks here. Carefully read the above to understand that.

Well, I don’t know, it might be like that if you follow the documentation and make a scoupe context or use a factory, but in any case, if you make it a singleton, there will be problems, well, maybe so be it) but I’m not used to this) because .Net controls the use of memory, never- I wouldn’t have thought that the context of the database would violate it, that’s why there were some problems) well, I solved them

Read more comments on GitHub >

github_iconTop Results From Across the Web

Change Tracking - EF Core
Overview of change tracking for EF Core. ... Tracking from queries; Simple query and update; Query then insert, update, and delete.
Read more >
Extract Changes (Feature Service)—ArcGIS REST APIs
To enable or disable change tracking on an existing feature service, add or remove the ChangeTracking capability to or from the feature service....
Read more >
ChangeTracker in Entity Framework Core
Learn how the ChangeTracker keeps track entities and their EntityState in Entity ... All the new entities without key property value, added in...
Read more >
OmniPlan 2 for Mac User Manual - Working with Resources
Select a resource or group in the outline, then press the Delete key. · Select the item, then click the Remove button (minus...
Read more >
Viewing, Editing, and Deleting Employee Change Tracking ...
Viewing, Editing, and Deleting Employee Change Tracking Records. In Reporting and Analytics, click Labor Management, and then click Human Resources.
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