public void Can_add_container_mappings()
        {
            var mapping = new DbDatabaseMapping();

            Assert.Empty(mapping.EntityContainerMappings);

            var containerMapping = new EntityContainerMapping(new EntityContainer());
            mapping.AddEntityContainerMapping(containerMapping);

            Assert.Same(containerMapping, mapping.EntityContainerMappings.Single());
        }
        public void Can_add_container_mappings()
        {
            var mapping = new DbDatabaseMapping();

            Assert.Empty(mapping.EntityContainerMappings);

            var containerMapping = new EntityContainerMapping(new EntityContainer());

            mapping.AddEntityContainerMapping(containerMapping);

            Assert.Same(containerMapping, mapping.EntityContainerMappings.Single());
        }
        public static DbModel Build(SimpleMappingContext mappingContext)
        {
            Debug.Assert(mappingContext != null, "mappingContext != null");

            var databaseMapping =
                new DbDatabaseMapping
                    {
                        Database = mappingContext.StoreModel,
                        Model = BuildEntityModel(mappingContext)
                    };

            databaseMapping.AddEntityContainerMapping(BuildEntityContainerMapping(mappingContext));

            return new DbModel(databaseMapping, new DbModelBuilder());
        }
        private static DbModel CreateDbModel(EdmModel conceptualModel, EdmModel storeModel)
        {
            if (storeModel == null)
            {
                storeModel = EdmModel.CreateStoreModel(
                    new DbProviderInfo("System.Data.SqlClient", "2012"),
                    SqlProviderServices.Instance.GetProviderManifest("2012"));                
            }

            if (conceptualModel == null)
            {
                conceptualModel = EdmModel.CreateConceptualModel();
            }

            var databaseMapping = new DbDatabaseMapping
            {
                Database = storeModel,
                Model = conceptualModel
            };

            databaseMapping.AddEntityContainerMapping(new EntityContainerMapping(databaseMapping.Model.Container));

            return new DbModel(databaseMapping, new DbModelBuilder());
        }
        public void UpdateMapping_updates_msl()
        {
            var edmx = XDocument.Parse(EdmxTemplate);
            var databaseMapping =
                new DbDatabaseMapping
                    {
                        Database = new EdmModel(DataSpace.SSpace),
                        Model = new EdmModel(DataSpace.SSpace),
                    };
            var model = new DbModel(databaseMapping, new DbModelBuilder());

            databaseMapping.AddEntityContainerMapping(
                new EntityContainerMapping(
                    databaseMapping.Model.Containers.Single(),
                    databaseMapping.Database.Containers.Single(),
                    null, false, false));

            new EdmxHelper(edmx).UpdateMapping(model);

            var storageModelsElements =
                edmx.Descendants(EdmxV3Namespace + "Mappings").Single();

            Assert.Equal(1, storageModelsElements.Elements().Count());
            Assert.Equal(
                XName.Get("Mapping", SchemaManager.GetMSLNamespaceName(EntityFrameworkVersion.Version3)),
                storageModelsElements.Elements().Single().Name);
        }