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 ShouldWriteJoin() { var mapping = new SubclassMapping(); mapping.AddJoin(new JoinMapping()); writer.VerifyXml(mapping) .Element("join").Exists(); }
public void JoinsCollectionHasSameCountAsMapping() { mapping.AddJoin(new JoinMapping()); inspector.Joins.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()); }