public void Generate(EdmEntityType entityType, DbDatabaseMapping databaseMapping)
        {
            //Contract.Requires(entityType != null);
            //Contract.Requires(databaseMapping != null);

            var entitySet = databaseMapping.Model.GetEntitySet(entityType);

            var entitySetMapping
                = databaseMapping.GetEntitySetMapping(entitySet)
                  ?? databaseMapping.AddEntitySetMapping(entitySet);

            var table
                = entitySetMapping.EntityTypeMappings.Any()
                      ? entitySetMapping.EntityTypeMappings.First().TypeMappingFragments.First().Table
                      : databaseMapping.Database.AddTable(entityType.GetRootType().Name);

            var entityTypeMappingFragment = new DbEntityTypeMappingFragment
                {
                    Table = table
                };

            var entityTypeMapping = new DbEntityTypeMapping
                {
                    EntityType = entityType,
                    IsHierarchyMapping = false
                };
            entityTypeMapping.TypeMappingFragments.Add(entityTypeMappingFragment);
            entityTypeMapping.SetClrType(entityType.GetClrType());

            entitySetMapping.EntityTypeMappings.Add(entityTypeMapping);

            new PropertyMappingGenerator(_providerManifest)
                .Generate(
                    entityType,
                    entityType.Properties,
                    entitySetMapping,
                    entityTypeMappingFragment,
                    new List<EdmProperty>(),
                    false);
        }
        public void GetEntityTypeMapping_should_return_mapping_for_type_by_clrType()
        {
            var databaseMapping = new DbDatabaseMapping()
                .Initialize(new EdmModel().Initialize(), new DbDatabaseMetadata());
            var entityType = new EdmEntityType { Name = "Foo" };
            entityType.SetClrType(typeof(object));
            var entityTypeMapping = new DbEntityTypeMapping { EntityType = entityType };
            entityTypeMapping.SetClrType(typeof(object));
            databaseMapping.AddEntitySetMapping(new EdmEntitySet()).EntityTypeMappings.Add(entityTypeMapping);

            Assert.Same(entityTypeMapping, databaseMapping.GetEntityTypeMapping(typeof(object)));
        }