Boostig Entity Framework Loops public class Product { public int ID { get; set; } public string ShortDescription { get; set; } public string Description { get; set; } } public class OldVariation { public int ID { get; set; } public int ProductID { get; set; } public virtual ProductModel Product { get; set; } } public class Variation { public int ID { get; set; } public int ProductID { get; set; } public virtual Product Product { get; set; } public string ShortDescription { get; set; } public string Description { get; set; } } var db = new AppContext(); var oldVariations= db.OldVariations.ToList(); foreach (var item in oldVariations ){ var variation = new VariationModel }; //if validations pass db.Variations.Add(variation); db.SaveChanges(); } This scenario takes ages if the number of OldVariations is very very large. Improvements:
var db = new AppContext(); var oldVariations= db.OldVariations.Include(o=>o.Product).ToList(); var counter = 0; var threshold = 50;db.Configuration.AutoDetectChangesEnabled = false; { var variation = new VariationModel //if validations pass db.Variations.Add(variation); counter++;
} db.SaveChanges(); Create Unique Index with Column that Accepts Null Values in Entity Framework Migration Sql("CREATE UNIQUE NONCLUSTERED INDEX [IX_ColumnWithNulls] ON [dbo].[Table]([ColumnWithNulls] ASC) WHERE ([ColumnWithNulls] IS NOT NULL"); Sql("CREATE UNIQUE NONCLUSTERED INDEX IX_Number on dbo.Orders(Number,ID) where Number IS NOT NULL"); |
tips (en) >