Ejemplo n.º 1
0
        /// <summary>
        /// Retrieve cached entities that were previously loaded.
        /// </summary>
        public static IEnumerable <EntityEntry <TEntity> > Local <TEntity>(this DbSet <TEntity> set, params object[] keyValues) where TEntity : class
        {
            var context = set.GetDbContext();
            var entries = context.ChangeTracker.Entries <TEntity>();

            if (keyValues.Any() == true)
            {
                var entityType = context.FindEntityType <TEntity>();
                var keys       = entityType.GetKeys();
                var i          = 0;
                foreach (var property in keys.SelectMany(x => x.Properties))
                {
                    var keyValue = keyValues[i];
                    entries = entries.Where(e => keyValue.Equals(e.Property(property.Name).CurrentValue));
                    i++;
                }
            }
            return(entries);
        }
Ejemplo n.º 2
0
 public static IEntityType FindEntityType <TEntity>(this DbSet <TEntity> set) where TEntity : class
 => set.GetDbContext().FindEntityType <TEntity>();