Add resource removal to ChangeTracking
See original GitHub issueI 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:
- Created a year ago
- Reactions:11
- Comments:50 (20 by maintainers)
Top 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 >
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
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.
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