public static (bool, int[]) AddTestData <TEntity>(this TrackingContext context, int quantity) where TEntity : class { for (int i = 0; i < quantity; i++) { var entity = Activator.CreateInstance <TEntity>(); var properties = entity.GetType().GetProperties(); foreach (var property in properties) { if (property.Name == "Id") { continue; } if (property.PropertyType == typeof(string)) { property.SetValue(entity, Random.GenerateString(10)); } } context.Set <TEntity>().Add(entity); } context.SaveChanges(); return(true, context.Set <TEntity>().Select(x => (int)x.GetType().GetProperty("Id").GetValue(x)).ToArray()); }