public void Map(ClassMappingBase classMap, Member member) { if (!(classMap is ClassMapping)) { return; } var idMapping = new IdMapping { ContainingEntityType = classMap.Type }; idMapping.AddDefaultColumn(new ColumnMapping() { Name = member.Name }); idMapping.Name = member.Name; idMapping.Type = new TypeReference(member.PropertyType); idMapping.Member = member; idMapping.SetDefaultValue("Generator", GetDefaultGenerator(member)); if (member.IsProperty && !member.CanWrite) { idMapping.Access = cfg.GetAccessStrategyForReadOnlyProperty(member).ToString(); } ((ClassMapping)classMap).Id = idMapping; }
public void Map(ClassMappingBase classMap, Member member) { if (!(classMap is ClassMapping)) { return; } var version = new VersionMapping { Name = member.Name, ContainingEntityType = classMap.Type, }; version.SetDefaultValue("Type", GetDefaultType(member)); version.AddDefaultColumn(new ColumnMapping { Name = member.Name }); if (member.IsProperty && !member.CanWrite) { version.Access = cfg.GetAccessStrategyForReadOnlyProperty(member).ToString(); } if (IsSqlTimestamp(member)) { version.Columns.Each(x => { x.SqlType = "timestamp"; x.NotNull = true; }); version.UnsavedValue = null; } ((ClassMapping)classMap).Version = version; }
void SetDefaultAccess(Member member, CollectionMapping mapping) { var resolvedAccess = MemberAccessResolver.Resolve(member); if (resolvedAccess != Access.Property && resolvedAccess != Access.Unset) { // if it's a property or unset then we'll just let NH deal with it, otherwise // set the access to be whatever we determined it might be mapping.Set(x => x.Access, Layer.Defaults, resolvedAccess.ToString()); } if (member.IsProperty && !member.CanWrite) { mapping.Set(x => x.Access, Layer.Defaults, cfg.GetAccessStrategyForReadOnlyProperty(member).ToString()); } }
private ManyToOneMapping CreateMapping(Member member) { var mapping = new ManyToOneMapping { Member = member }; mapping.SetDefaultValue(x => x.Name, member.Name); mapping.SetDefaultValue(x => x.Class, new TypeReference(member.PropertyType)); mapping.AddDefaultColumn(new ColumnMapping { Name = member.Name + "_id" }); if (member.IsProperty && !member.CanWrite) { mapping.Access = cfg.GetAccessStrategyForReadOnlyProperty(member).ToString(); } return(mapping); }
public void Map(ClassMappingBase classMap, Member member) { var mapping = new ComponentMapping(ComponentType.Component) { Name = member.Name, Member = member, ContainingEntityType = classMap.Type, Type = member.PropertyType, ColumnPrefix = cfg.GetComponentColumnPrefix(member) }; if (member.IsProperty && !member.CanWrite) { mapping.Access = cfg.GetAccessStrategyForReadOnlyProperty(member).ToString(); } mapper.FlagAsMapped(member.PropertyType); mapper.MergeMap(member.PropertyType, mapping, new List <Member>()); classMap.AddComponent(mapping); }
private void ConfigureModel(Member member, ICollectionMapping mapping, ClassMappingBase classMap, Type parentSide) { // TODO: Make the child type safer mapping.SetDefaultValue(x => x.Name, member.Name); mapping.Relationship = CreateManyToMany(member, member.PropertyType.GetGenericArguments()[0], classMap.Type); mapping.ContainingEntityType = classMap.Type; mapping.ChildType = member.PropertyType.GetGenericArguments()[0]; mapping.Member = member; if (member.IsProperty && !member.CanWrite) { mapping.Access = cfg.GetAccessStrategyForReadOnlyProperty(member).ToString(); } SetKey(member, classMap, mapping); if (parentSide != member.DeclaringType) { mapping.Inverse = true; } }
public ExternalComponentMapping Resolve(ComponentResolutionContext context, IEnumerable <IExternalComponentMappingProvider> componentProviders) { // this will only be called if there was no ComponentMap found var mapping = new ExternalComponentMapping(ComponentType.Component) { Member = context.ComponentMember, ContainingEntityType = context.EntityType, }; mapping.Set(x => x.Name, Layer.Defaults, context.ComponentMember.Name); mapping.Set(x => x.Type, Layer.Defaults, context.ComponentType); if (context.ComponentMember.IsProperty && !context.ComponentMember.CanWrite) { mapping.Set(x => x.Access, Layer.Defaults, cfg.GetAccessStrategyForReadOnlyProperty(context.ComponentMember).ToString()); } mapper.FlagAsMapped(context.ComponentType); mapper.MergeMap(context.ComponentType, mapping, new List <Member>()); return(mapping); }
public void Map(ClassMappingBase classMap, Member member) { if (member.DeclaringType != classMap.Type) { return; } var mapping = collections.CreateCollectionMapping(member.PropertyType); mapping.ContainingEntityType = classMap.Type; mapping.Member = member; mapping.SetDefaultValue(x => x.Name, member.Name); if (member.IsProperty && !member.CanWrite) { mapping.Access = cfg.GetAccessStrategyForReadOnlyProperty(member).ToString(); } keys.SetKey(member, classMap, mapping); SetElement(member, classMap, mapping); classMap.AddCollection(mapping); }