internal DbDatabaseMapping BuildCeMapping(DbModelBuilder modelBuilder) { // Build and clone to check for idempotency issues. modelBuilder.Build(ProviderRegistry.SqlCe4_ProviderInfo); var clone = modelBuilder.Clone(); return(clone.Build(ProviderRegistry.SqlCe4_ProviderInfo).DatabaseMapping); }
/// <summary> /// Writes csdl, msdl, and ssdl files into the current directory for the model generated from /// the given model builder. /// </summary> /// <param name="builder"> The builder. </param> /// <param name="filename"> The base filename to use for csdl, msdl, and sssl files. </param> public static void WriteMetadataFiles(DbModelBuilder builder, string filename) { var xml = new StringBuilder(); EdmxWriter.WriteEdmx( builder.Build(new DbProviderInfo("System.Data.SqlClient", "2008")), XmlWriter.Create(xml)); WriteMetadataFiles(xml.ToString(), filename); }
/// <summary> /// Writes an edmx file into the current directory for the model generated from the given model builder. /// </summary> /// <param name="builder"> The builder. </param> /// <param name="filename"> The filename to use for the edmx file. </param> public static void WriteEdmx(DbModelBuilder builder, string filename) { EdmxWriter.WriteEdmx( builder.Build(new DbProviderInfo("System.Data.SqlClient", "2008")), XmlWriter.Create(filename)); }
protected void VerifySetsAreInitialized <TContext>( DbCompiledModelContents contents, DbProviderInfo providerInfo = null) where TContext : SimpleModelContextWithNoData { providerInfo = providerInfo ?? ProviderRegistry.Sql2008_ProviderInfo; // Arrange // DbCompiledModel creation as appropriate for the various model content options var builder = new DbModelBuilder(); switch (contents) { case DbCompiledModelContents.IsEmpty: // Do nothing as builder has already been initialized break; case DbCompiledModelContents.IsSubset: // Product is not defined here builder.Entity <Category>(); break; case DbCompiledModelContents.IsSuperset: builder.Entity <Category>(); builder.Entity <Product>(); builder.Entity <Login>(); break; case DbCompiledModelContents.Match: builder.Entity <Category>(); builder.Entity <Product>(); break; case DbCompiledModelContents.DontMatch: builder.Entity <FeaturedProduct>(); builder.Entity <Login>(); break; default: throw new ArgumentException("Invalid DbCompiledModelContents Arguments passed in, " + contents); } var model = builder.Build(providerInfo).Compile(); // Act using (var context = (TContext)Activator.CreateInstance(typeof(TContext), model)) { // Verification as appropriate for the various model content options switch (contents) { case DbCompiledModelContents.IsEmpty: Assert.NotNull(context.Categories); Assert.NotNull(context.Products); context.Assert <Category>().IsNotInModel(); context.Assert <Product>().IsNotInModel(); break; case DbCompiledModelContents.IsSubset: Assert.NotNull(context.Categories); Assert.NotNull(context.Products); context.Assert <Category>().IsInModel(); context.Assert <Product>().IsInModel(); // reachability break; case DbCompiledModelContents.IsSuperset: Assert.NotNull(context.Categories); Assert.NotNull(context.Products); context.Assert <Category>().IsInModel(); context.Assert <Product>().IsInModel(); context.Assert <Login>().IsInModel(); break; case DbCompiledModelContents.Match: Assert.NotNull(context.Categories); Assert.NotNull(context.Products); context.Assert <Category>().IsInModel(); context.Assert <Product>().IsInModel(); context.Assert <Login>().IsNotInModel(); break; case DbCompiledModelContents.DontMatch: Assert.NotNull(context.Categories); Assert.NotNull(context.Products); context.Assert <Login>().IsInModel(); context.Assert <FeaturedProduct>().IsInModel(); break; default: throw new ArgumentException("Invalid DbCompiledModelContents Arguments passed in, " + contents); } } }