SubclassMapping IIndeterminateSubclassMappingProvider.GetSubclassMapping(SubclassType type) { var mapping = new SubclassMapping(type); GenerateNestedSubclasses(mapping); attributes.SetDefault(x => x.Type, typeof(T)); attributes.SetDefault(x => x.Name, typeof(T).AssemblyQualifiedName); attributes.SetDefault(x => x.DiscriminatorValue, typeof(T).Name); // TODO: un-hardcode this var key = new KeyMapping(); key.AddDefaultColumn(new ColumnMapping { Name = typeof(T).BaseType.Name + "_id" }); attributes.SetDefault(x => x.TableName, GetDefaultTableName()); attributes.SetDefault(x => x.Key, key); // TODO: this is nasty, we should find a better way mapping.OverrideAttributes(attributes.CloneInner()); foreach (var join in joins) { mapping.AddJoin(join); } foreach (var property in properties) { mapping.AddProperty(property.GetPropertyMapping()); } foreach (var component in components) { mapping.AddComponent(component.GetComponentMapping()); } foreach (var oneToOne in oneToOnes) { mapping.AddOneToOne(oneToOne.GetOneToOneMapping()); } foreach (var collection in collections) { mapping.AddCollection(collection.GetCollectionMapping()); } foreach (var reference in references) { mapping.AddReference(reference.GetManyToOneMapping()); } foreach (var any in anys) { mapping.AddAny(any.GetAnyMapping()); } return(mapping.DeepClone()); }
public void ShouldWriteBag() { var mapping = new SubclassMapping(SubclassType.JoinedSubclass); mapping.AddCollection(CollectionMapping.Bag()); writer.VerifyXml(mapping) .Element("bag").Exists(); }
public void ShouldWriteList() { var mapping = new SubclassMapping(); mapping.AddCollection(new ListMapping()); writer.VerifyXml(mapping) .Element("list").Exists(); }
public void ShouldWriteSet() { var mapping = new SubclassMapping(SubclassType.Subclass); mapping.AddCollection(CollectionMapping.Set()); writer.VerifyXml(mapping) .Element("set").Exists(); }
public void ShouldWriteBag() { var mapping = new SubclassMapping(); mapping.AddCollection(new BagMapping()); writer.VerifyXml(mapping) .Element("bag").Exists(); }
public void ShouldWriteMap() { var mapping = new SubclassMapping(SubclassType.Subclass); mapping.AddCollection(new MapMapping()); writer.VerifyXml(mapping) .Element("map").Exists(); }
public void ShouldWriteBag() { var mapping = new SubclassMapping(); mapping.AddCollection(new BagMapping()); writer.VerifyXml(mapping) .Element("bag").Exists(); }
public void Should_write_the_collections() { var subclassMapping = new SubclassMapping(); subclassMapping.AddCollection(new BagMapping()); _mocker.Get<IHbmWriter<ICollectionMapping>>() .Expect(x => x.Write(subclassMapping.Collections.First())).Return(new HbmBag()); _subclassWriter.VerifyXml(subclassMapping) .Element("bag").Exists(); }
SubclassMapping ISubclassMappingProvider.GetSubclassMapping() { var mapping = new SubclassMapping(SubclassType.JoinedSubclass, attributes.CloneInner()); mapping.Key = new KeyMapping { ContainingEntityType = typeof(TSubclass) }; mapping.Name = typeof(TSubclass).AssemblyQualifiedName; mapping.Type = typeof(TSubclass); foreach (var column in columns) { mapping.Key.AddColumn(column); } foreach (var property in properties) { mapping.AddProperty(property.GetPropertyMapping()); } foreach (var component in components) { mapping.AddComponent(component.GetComponentMapping()); } foreach (var oneToOne in oneToOnes) { mapping.AddOneToOne(oneToOne.GetOneToOneMapping()); } foreach (var collection in collections) { mapping.AddCollection(collection.GetCollectionMapping()); } foreach (var reference in references) { mapping.AddReference(reference.GetManyToOneMapping()); } foreach (var any in anys) { mapping.AddAny(any.GetAnyMapping()); } return(mapping); }
SubclassMapping ISubclassMappingProvider.GetSubclassMapping() { var mapping = new SubclassMapping(SubclassType.JoinedSubclass, attributes.Clone()); mapping.Set(x => x.Key, Layer.Defaults, new KeyMapping { ContainingEntityType = typeof(TSubclass) }); mapping.Set(x => x.Name, Layer.Defaults, typeof(TSubclass).AssemblyQualifiedName); mapping.Set(x => x.Type, Layer.Defaults, typeof(TSubclass)); foreach (var column in columns) { mapping.Key.AddColumn(Layer.Defaults, column); } foreach (var property in providers.Properties) { mapping.AddProperty(property.GetPropertyMapping()); } foreach (var component in providers.Components) { mapping.AddComponent(component.GetComponentMapping()); } foreach (var oneToOne in providers.OneToOnes) { mapping.AddOneToOne(oneToOne.GetOneToOneMapping()); } foreach (var collection in providers.Collections) { mapping.AddCollection(collection.GetCollectionMapping()); } foreach (var reference in providers.References) { mapping.AddReference(reference.GetManyToOneMapping()); } foreach (var any in providers.Anys) { mapping.AddAny(any.GetAnyMapping()); } return(mapping); }
SubclassMapping ISubclassMappingProvider.GetSubclassMapping() { var mapping = new SubclassMapping(SubclassType.Subclass, attributes.Clone()); if (discriminatorValue != null) { mapping.Set(x => x.DiscriminatorValue, Layer.Defaults, discriminatorValue); } mapping.Set(x => x.Type, Layer.Defaults, typeof(TSubclass)); mapping.Set(x => x.Name, Layer.Defaults, typeof(TSubclass).AssemblyQualifiedName); foreach (var property in providers.Properties) { mapping.AddProperty(property.GetPropertyMapping()); } foreach (var component in providers.Components) { mapping.AddComponent(component.GetComponentMapping()); } foreach (var oneToOne in providers.OneToOnes) { mapping.AddOneToOne(oneToOne.GetOneToOneMapping()); } foreach (var collection in providers.Collections) { mapping.AddCollection(collection.GetCollectionMapping()); } foreach (var reference in providers.References) { mapping.AddReference(reference.GetManyToOneMapping()); } foreach (var any in providers.Anys) { mapping.AddAny(any.GetAnyMapping()); } subclassMappings.Each(mapping.AddSubclass); return(mapping); }
public void ShouldWriteBag() { var mapping = new SubclassMapping(SubclassType.JoinedSubclass); mapping.AddCollection(CollectionMapping.Bag()); writer.VerifyXml(mapping) .Element("bag").Exists(); }
public void ShouldWriteSet() { var mapping = new SubclassMapping(SubclassType.Subclass); mapping.AddCollection(CollectionMapping.Set()); writer.VerifyXml(mapping) .Element("set").Exists(); }
public void ShouldWriteList() { var mapping = new SubclassMapping(SubclassType.JoinedSubclass); mapping.AddCollection(new ListMapping()); writer.VerifyXml(mapping) .Element("list").Exists(); }
public void CollectionsCollectionHasSameCountAsMapping() { mapping.AddCollection(new BagMapping()); inspector.Collections.Count().ShouldEqual(1); }
SubclassMapping IIndeterminateSubclassMappingProvider.GetSubclassMapping(SubclassType type) { var mapping = new SubclassMapping(type); GenerateNestedSubclasses(mapping); attributes.Set("Type", Layer.Defaults, typeof(T)); attributes.Set("Name", Layer.Defaults, typeof(T).AssemblyQualifiedName); attributes.Set("DiscriminatorValue", Layer.Defaults, typeof(T).Name); // TODO: un-hardcode this Type baseType = typeof(T).BaseType ?? attributes.Get("Extends") as Type; if (baseType != null) { var key = new KeyMapping(); key.AddColumn(Layer.Defaults, new ColumnMapping(baseType.Name + "_id")); attributes.Set("Key", Layer.Defaults, key); } attributes.Set("TableName", Layer.Defaults, GetDefaultTableName()); // TODO: this is nasty, we should find a better way mapping.OverrideAttributes(attributes.Clone()); foreach (var join in joins) { mapping.AddJoin(join); } foreach (var provider in providers.OrderedProviders) { var mappingProviderObj = provider.Item2; switch (provider.Item1) { case MappingProviderStore.ProviderType.Property: mapping.AddProperty(((IPropertyMappingProvider)mappingProviderObj).GetPropertyMapping()); break; case MappingProviderStore.ProviderType.Component: mapping.AddComponent(((IComponentMappingProvider)mappingProviderObj).GetComponentMapping()); break; case MappingProviderStore.ProviderType.OneToOne: mapping.AddOneToOne(((IOneToOneMappingProvider)mappingProviderObj).GetOneToOneMapping()); break; case MappingProviderStore.ProviderType.Collection: mapping.AddCollection(((ICollectionMappingProvider)mappingProviderObj).GetCollectionMapping()); break; case MappingProviderStore.ProviderType.ManyToOne: mapping.AddReference(((IManyToOneMappingProvider)mappingProviderObj).GetManyToOneMapping()); break; case MappingProviderStore.ProviderType.Any: mapping.AddAny(((IAnyMappingProvider)mappingProviderObj).GetAnyMapping()); break; case MappingProviderStore.ProviderType.Subclass: case MappingProviderStore.ProviderType.Filter: case MappingProviderStore.ProviderType.StoredProcedure: case MappingProviderStore.ProviderType.Join: case MappingProviderStore.ProviderType.Identity: case MappingProviderStore.ProviderType.CompositeId: case MappingProviderStore.ProviderType.NaturalId: case MappingProviderStore.ProviderType.Version: case MappingProviderStore.ProviderType.Discriminator: case MappingProviderStore.ProviderType.Tupilizer: default: throw new Exception("Internal Error"); } } return(mapping.DeepClone()); }
SubclassMapping IIndeterminateSubclassMappingProvider.GetSubclassMapping(SubclassType type) { var mapping = new SubclassMapping(type); GenerateNestedSubclasses(mapping); attributes.Set("Type", Layer.Defaults, typeof(T)); attributes.Set("Name", Layer.Defaults, typeof(T).AssemblyQualifiedName); attributes.Set("DiscriminatorValue", Layer.Defaults, typeof(T).Name); // TODO: un-hardcode this Type baseType = typeof(T).BaseType ?? attributes.Get("Extends") as Type; if (baseType != null) { var key = new KeyMapping(); key.AddColumn(Layer.Defaults, new ColumnMapping(baseType.Name + "_id")); attributes.Set("Key", Layer.Defaults, key); } attributes.Set("TableName", Layer.Defaults, GetDefaultTableName()); // TODO: this is nasty, we should find a better way mapping.OverrideAttributes(attributes.Clone()); foreach (var join in joins) { mapping.AddJoin(join); } foreach (var property in providers.Properties) { mapping.AddProperty(property.GetPropertyMapping()); } foreach (var component in providers.Components) { mapping.AddComponent(component.GetComponentMapping()); } foreach (var oneToOne in providers.OneToOnes) { mapping.AddOneToOne(oneToOne.GetOneToOneMapping()); } foreach (var collection in providers.Collections) { mapping.AddCollection(collection.GetCollectionMapping()); } foreach (var reference in providers.References) { mapping.AddReference(reference.GetManyToOneMapping()); } foreach (var any in providers.Anys) { mapping.AddAny(any.GetAnyMapping()); } return(mapping.DeepClone()); }