public void _08_ManyToMany() { const string connectionString = "Server=localhost;Database=ManyToMany;Trusted_Connection=true"; var sqlServerGenerator = new SqlServerGeneratorFactory( connectionString); var reverseFactory = new ReverseFactory( sqlServerGenerator, new EntityNamespace("Fact"), "Context"); var code = new StringBuilder(); reverseFactory.WriteTo(code); var path = Path.GetDirectoryName( Assembly.GetExecutingAssembly().Location); var compiler = new CompileContext( code.ToString(), Path.Combine(path, @"..\..\..\..\packages\EntityFramework.6.2.0\lib\net45\EntityFramework.dll"), Path.Combine(path, @"..\..\..\..\packages\EntityFramework.6.2.0\lib\net45\EntityFramework.SqlServer.dll")); compiler.Assembly.Should().NotBeNull(); Assembly.Load(compiler.Assembly.FullName) .Should().NotBeNull(); var contextType = compiler.Assembly.GetType("Fact.Models.Context"); contextType.Should().NotBeNull(); }
//[Fact(Skip="Moved to Core, but test hasn't updated.")] public void DatabaseShouldDeployFromReverseEngineer() { var entityNamespace = new EntityNamespace("Fact"); var sampleGeneratorFactory = new SampleGeneratorFactory( CodeFirstGen.Simple.Csdl(), CodeFirstGen.Simple.Ssdl(), CodeFirstGen.Simple.Msdl()); var factory = new ReverseFactory( sampleGeneratorFactory, entityNamespace, "Context"); var code = new StringBuilder(); factory.WriteTo(code); var path = Path.GetDirectoryName( Assembly.GetExecutingAssembly().Location); var compiler = new CompileContext( code.ToString(), Path.Combine(path, @"..\..\..\..\packages\EntityFramework.6.2.0\lib\net45\EntityFramework.dll"), Path.Combine(path, @"..\..\..\..\packages\EntityFramework.SqlServerCompact.6.2.0\lib\net45\EntityFramework.SqlServerCompact.dll")); var contextType = compiler.GetContextType(); var sqlCompactContextFactory = new SqlCompactContextFactory(); using (var context = sqlCompactContextFactory.Create(x => (DbContext)Activator.CreateInstance(contextType, x))) { context.Database.CreateIfNotExists(); var tableType = compiler.GetType("Fact.Models.Table"); var table1 = (dynamic)Activator.CreateInstance(tableType); table1.Name = "Donkey"; dynamic dc = context; dc.Tables.Add(table1); dc.SaveChanges(); } using (dynamic context = sqlCompactContextFactory.Create(x => (DbContext)Activator.CreateInstance(contextType, x))) { var name = (string)System.Linq.Queryable.First(context.Tables).Name; name.Should().Be("Donkey"); } }