protected virtual CompositeIdentityPart <T> KeyReference(Member member, IEnumerable <string> columnNames, Action <KeyManyToOnePart> customMapping) { onMemberMapped(member); var key = new KeyManyToOneMapping { ContainingEntityType = typeof(T) }; key.Set(x => x.Name, Layer.Defaults, member.Name); key.Set(x => x.Class, Layer.Defaults, new TypeReference(member.PropertyType)); foreach (var column in columnNames) { var columnMapping = new ColumnMapping(); columnMapping.Set(x => x.Name, Layer.Defaults, column); key.AddColumn(columnMapping); } var keyPart = new KeyManyToOnePart(key); if (customMapping != null) { customMapping(keyPart); } keys.Add(key); return(this); }
ColumnMapping CreateColumn(string column) { var columnMapping = new ColumnMapping(columnAttributes.Clone()); columnMapping.Set(x => x.Name, Layer.Defaults, column); return(columnMapping); }
public override void ProcessColumn(ColumnMapping columnMapping) { if (prefixes.Any()) { columnMapping.Set(x => x.Name, Layer.UserSupplied, GetPrefix() + columnMapping.Name); } }
protected virtual CompositeIdentityPart <T> KeyProperty(Member member, string columnName, Action <KeyPropertyPart> customMapping) { var type = member.PropertyType; if (type.IsEnum) { type = typeof(GenericEnumMapper <>).MakeGenericType(type); } var key = new KeyPropertyMapping { ContainingEntityType = typeof(T) }; key.Set(x => x.Name, Layer.Defaults, member.Name); key.Set(x => x.Type, Layer.Defaults, new TypeReference(type)); if (customMapping != null) { var part = new KeyPropertyPart(key); customMapping(part); } if (!string.IsNullOrEmpty(columnName)) { var columnMapping = new ColumnMapping(); columnMapping.Set(x => x.Name, Layer.Defaults, columnName); key.AddColumn(columnMapping); } keys.Add(key); return(this); }
/// <summary> /// Specifies the column name for the index or key of the dictionary. /// </summary> /// <param name="indexColumnName">Column name</param> public void Column(string indexColumnName) { var column = new ColumnMapping(sharedColumnAttributes); column.Set(x => x.Name, Layer.UserSupplied, indexColumnName); mapping.AddColumn(Layer.UserSupplied, column); }
PropertyMapping IPropertyMappingProvider.GetPropertyMapping() { var mapping = new PropertyMapping(attributes.Clone()) { ContainingEntityType = parentType, Member = member }; if (columns.Count() == 0 && !mapping.IsSpecified("Formula")) { var columnMapping = new ColumnMapping(columnAttributes.Clone()); columnMapping.Set(x => x.Name, Layer.Defaults, member.Name); mapping.AddColumn(Layer.Defaults, columnMapping); } foreach (var column in columns) { mapping.AddColumn(Layer.UserSupplied, column); } foreach (var column in mapping.Columns) { if (member.PropertyType.IsNullable() && member.PropertyType.IsEnum()) { column.Set(x => x.NotNull, Layer.Defaults, false); } column.MergeAttributes(columnAttributes); } mapping.Set(x => x.Name, Layer.Defaults, mapping.Member.Name); mapping.Set(x => x.Type, Layer.Defaults, GetDefaultType()); return(mapping); }
public void Map(ClassMappingBase classMap, Member member) { if (!(classMap is ClassMapping)) { return; } var version = new VersionMapping { ContainingEntityType = classMap.Type, }; version.Set(x => x.Name, Layer.Defaults, member.Name); version.Set(x => x.Type, Layer.Defaults, GetDefaultType(member)); var columnMapping = new ColumnMapping(); columnMapping.Set(x => x.Name, Layer.Defaults, member.Name); version.AddColumn(Layer.Defaults, columnMapping); SetDefaultAccess(member, version); if (IsSqlTimestamp(member)) { version.Columns.Each(column => { column.Set(x => x.SqlType, Layer.Defaults, "timestamp"); column.Set(x => x.NotNull, Layer.Defaults, true); }); version.Set(x => x.UnsavedValue, Layer.Defaults, null); } ((ClassMapping)classMap).Set(x => x.Version, Layer.Defaults, version); }
private void MapInheritanceTree(Type classType, ClassMappingBase mapping, IList <Member> mappedMembers) { var discriminatorSet = HasDiscriminator(mapping); var isDiscriminated = cfg.IsDiscriminated(classType) || discriminatorSet; var mappingTypesWithLogicalParents = GetMappingTypesWithLogicalParents(); foreach (var inheritedClass in mappingTypesWithLogicalParents .Where(x => x.Value != null && x.Value.Type == classType) .Select(x => x.Key)) { var tempMapping = mapping as ClassMapping; var tempIsNull = tempMapping == null; if (isDiscriminated && !discriminatorSet && !tempIsNull) { var discriminatorColumn = cfg.GetDiscriminatorColumn(classType); var discriminator = new DiscriminatorMapping { ContainingEntityType = classType, }; discriminator.Set(x => x.Type, Layer.Defaults, new TypeReference(typeof(string))); var columnMapping = new ColumnMapping(); columnMapping.Set(x => x.Name, Layer.Defaults, discriminatorColumn); discriminator.AddColumn(Layer.Defaults, columnMapping); tempMapping.Set(x => x.Discriminator, Layer.Defaults, discriminator); discriminatorSet = true; } SubclassMapping subclassMapping; var tempSubClassMap = mapping as SubclassMapping; if (!tempIsNull && tempMapping.IsUnionSubclass || tempSubClassMap != null && tempSubClassMap.SubclassType == SubclassType.UnionSubclass) { subclassMapping = new SubclassMapping(SubclassType.UnionSubclass); subclassMapping.Set(x => x.Type, Layer.Defaults, inheritedClass.Type); } else if (isDiscriminated || tempSubClassMap != null && tempSubClassMap.SubclassType == SubclassType.Subclass) { subclassMapping = new SubclassMapping(SubclassType.Subclass); subclassMapping.Set(x => x.Type, Layer.Defaults, inheritedClass.Type); } else { subclassMapping = new SubclassMapping(SubclassType.JoinedSubclass); subclassMapping.Set(x => x.Type, Layer.Defaults, inheritedClass.Type); subclassMapping.Set(x => x.Key, Layer.Defaults, new KeyMapping()); var columnMapping = new ColumnMapping(); columnMapping.Set(x => x.Name, Layer.Defaults, mapping.Type.Name + "_id"); subclassMapping.Key.AddColumn(Layer.Defaults, columnMapping); } // track separate set of properties for each sub-tree within inheritance hierarchy var subclassMembers = new List <Member>(mappedMembers); MapSubclass(subclassMembers, subclassMapping, inheritedClass); mapping.AddSubclass(subclassMapping); MergeMap(inheritedClass.Type, subclassMapping, subclassMembers); } }
public TParent Add(string name) { var mapping = new ColumnMapping(); mapping.Set(x => x.Name, Layer.UserSupplied, name); columns.Add(mapping); return(parent); }
public KeyPropertyPart ColumnName(string columnName) { var column = new ColumnMapping(); column.Set(x => x.Name, Layer.UserSupplied, columnName); mapping.AddColumn(column); return(this); }
JoinMapping IJoinMappingProvider.GetJoinMapping() { var mapping = new JoinMapping(attributes.Clone()) { ContainingEntityType = typeof(T) }; if (columns.Count == 0) { var columnMapping = new ColumnMapping(); columnMapping.Set(x => x.Name, Layer.Defaults, typeof(T).Name + "_id"); mapping.Key.AddColumn(Layer.Defaults, columnMapping); } else { foreach (var column in columns) { var columnMapping = new ColumnMapping(); columnMapping.Set(x => x.Name, Layer.Defaults, column); mapping.Key.AddColumn(Layer.UserSupplied, columnMapping); } } foreach (var property in providers.Properties) { mapping.AddProperty(property.GetPropertyMapping()); } foreach (var component in providers.Components) { mapping.AddComponent(component.GetComponentMapping()); } foreach (var reference in providers.References) { mapping.AddReference(reference.GetManyToOneMapping()); } foreach (var any in providers.Anys) { mapping.AddAny(any.GetAnyMapping()); } foreach (var collection in providers.Collections) { mapping.AddCollection(collection.GetCollectionMapping()); } foreach (var storedProcedure in providers.StoredProcedures) { mapping.AddStoredProcedure(storedProcedure.GetStoredProcedureMapping()); } return(mapping); }
public TParent Add(string columnName, Action <ColumnPart> customColumnMapping) { var mapping = new ColumnMapping(); mapping.Set(x => x.Name, Layer.UserSupplied, columnName); var part = new ColumnPart(mapping); customColumnMapping(part); columns.Add(mapping); return(parent); }
void ICollectionInstance.AsList() { mapping.Collection = Collection.List; if (mapping.Index == null) { var indexMapping = new IndexMapping(); var columnMapping = new ColumnMapping(); columnMapping.Set(x => x.Name, Layer.Defaults, "Index"); indexMapping.AddColumn(Layer.Defaults, columnMapping); mapping.Set(x => x.Index, Layer.Defaults, indexMapping); } ; }
/// <summary> /// Use a list collection with an index /// </summary> /// <param name="customIndexMapping">Index mapping</param> public T AsList(Action <ListIndexPart> customIndexMapping) { collectionBuilder = attrs => CollectionMapping.List(attrs); CreateListIndexMapping(customIndexMapping); if (indexMapping.Columns.IsEmpty()) { var columnMapping = new ColumnMapping(); columnMapping.Set(x => x.Name, Layer.Defaults, "Index"); indexMapping.AddColumn(Layer.Defaults, columnMapping); } return((T)this); }
AnyMapping IAnyMappingProvider.GetAnyMapping() { var mapping = new AnyMapping(attributes.Clone()); if (typeColumns.Count() == 0) { throw new InvalidOperationException("<any> mapping is not valid without specifying an Entity Type Column"); } if (identifierColumns.Count() == 0) { throw new InvalidOperationException("<any> mapping is not valid without specifying an Entity Identifier Column"); } if (!idTypeSet) { throw new InvalidOperationException("<any> mapping is not valid without specifying an IdType"); } mapping.ContainingEntityType = entity; mapping.Set(x => x.Name, Layer.Defaults, member.Name); if (!mapping.IsSpecified("MetaType")) { mapping.Set(x => x.MetaType, Layer.Defaults, new TypeReference(member.PropertyType)); } if (metaValues.Count() > 0) { metaValues.Each(mapping.AddMetaValue); mapping.Set(x => x.MetaType, Layer.Defaults, new TypeReference(typeof(string))); } foreach (var column in typeColumns) { var columnMapping = new ColumnMapping(); columnMapping.Set(x => x.Name, Layer.Defaults, column); mapping.AddTypeColumn(Layer.UserSupplied, columnMapping); } foreach (var column in identifierColumns) { var columnMapping = new ColumnMapping(); columnMapping.Set(x => x.Name, Layer.Defaults, column); mapping.AddIdentifierColumn(Layer.UserSupplied, columnMapping); } return(mapping); }
protected virtual NaturalIdPart <T> Property(Member member, string columnName) { var key = new PropertyMapping(); key.Set(x => x.Name, Layer.Defaults, member.Name); key.Set(x => x.Type, Layer.Defaults, new TypeReference(member.PropertyType)); var columnMapping = new ColumnMapping(); columnMapping.Set(x => x.Name, Layer.Defaults, columnName); key.AddColumn(Layer.UserSupplied, columnMapping); properties.Add(key); return(this); }
private void SetElement(Member property, ClassMappingBase classMap, CollectionMapping mapping) { var element = new ElementMapping { ContainingEntityType = classMap.Type, }; element.Set(x => x.Type, Layer.Defaults, new TypeReference(property.PropertyType.GetGenericArguments()[0])); var columnMapping = new ColumnMapping(); columnMapping.Set(x => x.Name, Layer.Defaults, cfg.SimpleTypeCollectionValueColumn(property)); element.AddColumn(Layer.Defaults, columnMapping); mapping.Set(x => x.Element, Layer.Defaults, element); }
static void SetKey(Member property, ClassMappingBase classMap, CollectionMapping mapping) { var columnName = property.DeclaringType.Name + "_id"; var key = new KeyMapping { ContainingEntityType = classMap.Type }; var columnMapping = new ColumnMapping(); columnMapping.Set(x => x.Name, Layer.Defaults, columnName); key.AddColumn(Layer.Defaults, columnMapping); mapping.Set(x => x.Key, Layer.Defaults, key); }
public IndexMapping GetIndexMapping() { var mapping = new IndexMapping(attributes.Clone()); mapping.ContainingEntityType = entity; columns.Each(name => { var columnMapping = new ColumnMapping(); columnMapping.Set(x => x.Name, Layer.Defaults, name); mapping.AddColumn(Layer.UserSupplied, columnMapping); }); return(mapping); }
/// <summary> /// Make this collection index /// </summary> /// <typeparam name="TIndex">Index type</typeparam> /// <param name="indexColumn">Index column</param> /// <param name="customIndexMapping">Index mapping</param> public T AsIndexedCollection <TIndex>(string indexColumn, Action <IndexPart> customIndexMapping) { CreateIndexMapping(customIndexMapping); indexMapping.Set(x => x.Type, Layer.Defaults, new TypeReference(typeof(TIndex))); if (indexMapping.Columns.IsEmpty()) { var columnMapping = new ColumnMapping(); columnMapping.Set(x => x.Name, Layer.Defaults, indexColumn); indexMapping.AddColumn(Layer.Defaults, columnMapping); } return((T)this); }
static ICollectionRelationshipMapping CreateManyToMany(Member property, Type child, Type parent) { var mapping = new ManyToManyMapping { ContainingEntityType = parent }; mapping.Set(x => x.Class, Layer.Defaults, new TypeReference(property.PropertyType.GetGenericArguments()[0])); var columnMapping = new ColumnMapping(); columnMapping.Set(x => x.Name, Layer.Defaults, child.Name + "_id"); mapping.AddColumn(Layer.Defaults, columnMapping); return(mapping); }
DiscriminatorMapping IDiscriminatorMappingProvider.GetDiscriminatorMapping() { var mapping = new DiscriminatorMapping(attributes.Clone()) { ContainingEntityType = entity, }; mapping.Set(x => x.Type, Layer.Defaults, discriminatorValueType); var columnMapping = new ColumnMapping(columnAttributes.Clone()); columnMapping.Set(x => x.Name, Layer.Defaults, columnName); mapping.AddColumn(Layer.Defaults, columnMapping); return(mapping); }
private ManyToOneMapping CreateMapping(Member member) { var mapping = new ManyToOneMapping { Member = member }; mapping.Set(x => x.Name, Layer.Defaults, member.Name); mapping.Set(x => x.Class, Layer.Defaults, new TypeReference(member.PropertyType)); var columnMapping = new ColumnMapping(); columnMapping.Set(x => x.Name, Layer.Defaults, member.Name + "_id"); mapping.AddColumn(Layer.Defaults, columnMapping); SetDefaultAccess(member, mapping); return(mapping); }
protected virtual NaturalIdPart <T> Reference(Member member, string columnName) { var key = new ManyToOneMapping { ContainingEntityType = typeof(T) }; key.Set(x => x.Name, Layer.Defaults, member.Name); key.Set(x => x.Class, Layer.Defaults, new TypeReference(member.PropertyType)); var columnMapping = new ColumnMapping(); columnMapping.Set(x => x.Name, Layer.Defaults, columnName); key.AddColumn(Layer.Defaults, columnMapping); manyToOnes.Add(key); return(this); }
private PropertyMapping GetPropertyMapping(Type type, Member property) { var mapping = new PropertyMapping { ContainingEntityType = type, Member = property }; var columnMapping = new ColumnMapping(); columnMapping.Set(x => x.Name, Layer.Defaults, property.Name); mapping.AddColumn(Layer.Defaults, columnMapping); mapping.Set(x => x.Name, Layer.Defaults, mapping.Member.Name); mapping.Set(x => x.Type, Layer.Defaults, GetDefaultType(property)); SetDefaultAccess(property, mapping); return(mapping); }
public void Map(ClassMappingBase classMap, Member member) { if (!(classMap is ClassMapping)) { return; } var idMapping = new IdMapping { ContainingEntityType = classMap.Type }; var columnMapping = new ColumnMapping(); columnMapping.Set(x => x.Name, Layer.Defaults, member.Name); idMapping.AddColumn(Layer.Defaults, columnMapping); idMapping.Set(x => x.Name, Layer.Defaults, member.Name); idMapping.Set(x => x.Type, Layer.Defaults, new TypeReference(member.PropertyType)); idMapping.Member = member; idMapping.Set(x => x.Generator, Layer.Defaults, GetDefaultGenerator(member)); SetDefaultAccess(member, idMapping); ((ClassMapping)classMap).Set(x => x.Id, Layer.Defaults, idMapping); }
IdMapping IIdentityMappingProvider.GetIdentityMapping() { var mapping = new IdMapping(attributes.Clone()) { ContainingEntityType = entityType }; if (columns.Count > 0) { foreach (var column in columns) { var columnMapping = new ColumnMapping(columnAttributes.Clone()); columnMapping.Set(x => x.Name, Layer.Defaults, column); mapping.AddColumn(Layer.UserSupplied, columnMapping); } } else if (HasNameSpecified) { var columnMapping = new ColumnMapping(columnAttributes.Clone()); columnMapping.Set(x => x.Name, Layer.Defaults, name); mapping.AddColumn(Layer.Defaults, columnMapping); } if (member != null) { mapping.Set(x => x.Name, Layer.Defaults, name); } mapping.Set(x => x.Type, Layer.Defaults, new TypeReference(identityType)); if (GeneratedBy.IsDirty) { mapping.Set(x => x.Generator, Layer.UserSupplied, GeneratedBy.GetGeneratorMapping()); } return(mapping); }
VersionMapping IVersionMappingProvider.GetVersionMapping() { var mapping = new VersionMapping(attributes.Clone()) { ContainingEntityType = entity }; mapping.Set(x => x.Name, Layer.Defaults, member.Name); mapping.Set(x => x.Type, Layer.Defaults, member.PropertyType == typeof(DateTime) ? new TypeReference("timestamp") : new TypeReference(member.PropertyType)); var defaultColumnMapping = new ColumnMapping(columnAttributes.Clone()); defaultColumnMapping.Set(x => x.Name, Layer.Defaults, member.Name); mapping.AddColumn(Layer.Defaults, defaultColumnMapping); columns.ForEach(column => { var columnMapping = new ColumnMapping(columnAttributes.Clone()); columnMapping.Set(x => x.Name, Layer.Defaults, column); mapping.AddColumn(Layer.UserSupplied, columnMapping); }); return(mapping); }
/// <summary> /// Specify the column name /// </summary> /// <param name="columnName">Column name</param> public ColumnPart Name(string columnName) { columnMapping.Set(x => x.Name, Layer.UserSupplied, columnName); return(this); }
public new void Length(int length) { mapping.Set(x => x.Length, Layer.Conventions, length); }