public static int SeedDatabase(this EfCoreContext context, string dataDirectory) { if (!(context.GetService <IDatabaseCreator>() as RelationalDatabaseCreator).Exists()) { throw new InvalidOperationException("The database does not exist. If you are using Migrations then run PMC command update-database to create it"); } var persons = context.Persons.Count(); if (persons == 0) { //context.Persons.Add(new Person("Amin","sahranavard","0323526462","09389723798")); //var contractor = new Contractor("Sample Contractor", "02111111111", "Sample Address", DateTime.Now); //var project = new Project("Sample Project", 0, DateTime.Now, DateTime.Now.AddDays(30)); //contractor.Projects.Add(project); //context.Contractors.Add(contractor); //context.ProjectRoadMaps.Add(new WorkPackage("PreCommissioning")); //context.ProjectRoadMaps.Add(new WorkPackage("Commissioning")); //context.LocationTypes.Add(new LocationType("Yard")); //context.LocationTypes.Add(new LocationType("Site")); //context.SaveChanges(); context.Database.ExecuteSqlCommand("CREATE TYPE [dbo].[UpdateTaskWFType] AS TABLE([ActivityId] [bigint] NOT NULL,[WF] [real] NOT NULL)"); context.Database.ExecuteSqlCommand("CREATE TYPE [dbo].[UpdateWBSWF] AS TABLE([Id][bigint] NOT NULL,[WF][real] NOT NULL)"); context.Database.ExecuteSqlCommand("Create PROCEDURE [dbo].[UpdateTaskWF](@MAsset UpdateTaskWFType READONLY) AS begin SET NOCOUNT OFF; MERGE INTO OrganizationResources.Activity b USING @MAsset a ON b.Id=a.ActivityId WHEN MATCHED Then update set b.WeightFactor=a.WF; end "); context.Database.ExecuteSqlCommand("CREATE PROCEDURE [dbo].[UpdateWBSWF](@MAsset UpdateWBSWF READONLY) AS begin SET NOCOUNT OFF; MERGE INTO OrganizationResources.ProjectWBS as b USING @MAsset a ON b.Id = a.Id WHEN MATCHED Then update set b.WF = a.WF; end"); } return(1); }
public static int SeedDatabase(this EfCoreContext context, string dataDirectory) { if (!(context.GetService <IDatabaseCreator>() as RelationalDatabaseCreator).Exists()) { throw new InvalidOperationException("The database does not exist. If you are using Migrations then run PMC command update-database to create it"); } var numBooks = context.Books.Count(); if (numBooks == 0) { //the database is emply so we fill it from a json file var books = BookJsonLoader.LoadBooks(Path.Combine(dataDirectory, SeedFileSubDirectory), SeedDataSearchName).ToList(); context.Books.AddRange(books); context.SaveChanges(); numBooks = books.Count + 1; context.ResetOrders(books); } return(numBooks); }
public static int SeedDatabase(this EfCoreContext context, string dataDirectory) { if (!(context.GetService <IDatabaseCreator>() as RelationalDatabaseCreator).Exists()) { throw new InvalidOperationException("The database does not exist. If you are using Migrations then run PMC command update-database to create it"); } var numBooks = context.Books.Count(); if (numBooks == 0) { //the database is emply so we fill it from a json file var books = BookJsonLoader.LoadBooks(Path.Combine(dataDirectory, SeedFileSubDirectory), SeedDataSearchName).ToList(); context.Books.AddRange(books); context.SaveChanges(); //We add this separately so that it has the highest Id. That will make it appear at the top of the default list context.Books.Add(SpecialBook.CreateSpecialBook()); context.SaveChanges(); numBooks = books.Count + 1; } return(numBooks); }