/// <summary> /// Drops database and fills with predefined data. Temporary solution. /// </summary> private static void ReinitializeDatabase(WorldContextFactory worldContextFactory) { using (var context = worldContextFactory.CreateDbContext()) { Console.WriteLine("Dropping database if exists"); context.Database.EnsureDeleted(); Console.WriteLine("Creating fresh database with dev data"); context.Database.EnsureCreated(); var testSpaceObject = new SpaceObject { Id = Guid.NewGuid(), Components = new List <SpaceObjectComponent> { new Transform { Id = Guid.NewGuid(), Position = new Vector2D(1e9, 2e9), Rotation = Math.PI / 3 } } }; context.SpaceObjects.Add(testSpaceObject); context.SaveChanges(); } }
protected SpaceObjectComponentActor(WorldContextFactory worldContextFactory, SpaceObjectComponent component) : base(component) { WorldContextFactory = worldContextFactory; using (var worldContext = worldContextFactory.CreateDbContext()) { // Unlike SpaceObjectActor, it is assumed here that component is already persisted in database. // Adding components to already existing SpaceObject is not needed now. Boolean idFound = worldContext .Components .Any(c => c.Id == component.Id); if (!idFound) { throw new ArgumentException("Component with given Id not found."); } } }