Skip to content

Instantly share code, notes, and snippets.

@mesuttalebi
Created February 25, 2020 09:41
Show Gist options
  • Save mesuttalebi/63e014bb36fb99d3a7f6f87e55d35811 to your computer and use it in GitHub Desktop.
Save mesuttalebi/63e014bb36fb99d3a7f6f87e55d35811 to your computer and use it in GitHub Desktop.
GetByIdNotracking Method added.
public virtual T GetByIdNoTracking(params object[] id)
{
_context.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;
var item = DbSet.Find(id);
if (item != null)
if (typeof(ISoftDeleteEnabled).IsAssignableFrom(typeof(T)))
item = (bool)typeof(T).GetProperty("IsDeleted").GetValue(item) == false ? item : null;
_context.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.TrackAll;
return item;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment