public void Map(ClassMappingBase classMap, Member member) { if (!(classMap is ClassMapping)) { return; } var identity = ((ClassMapping) classMap).Id; if (identity == null) { 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); identity = idMapping; } else { if (identity is IdMapping) { var idMapping = identity as IdMapping; var compositeId = new CompositeIdMapping {ContainingEntityType = classMap.Type}; var idKeyPropertyMapping = GetKeyPropertyMapping(classMap.Type, idMapping.Name, idMapping.Type.GetUnderlyingSystemType()); var keyPropertyMapping = GetKeyPropertyMapping(classMap.Type, member.Name, member.PropertyType); compositeId.AddKey(idKeyPropertyMapping); compositeId.AddKey(keyPropertyMapping); identity = compositeId; } else if (identity is CompositeIdMapping) { var compositeId = identity as CompositeIdMapping; var keyPropertyMapping = GetKeyPropertyMapping(classMap.Type, member.Name, member.PropertyType); compositeId.AddKey(keyPropertyMapping); identity = compositeId; } else { throw new NotImplementedException( string.Format("Mayank: Fluent nhibernate not exended to support type '{0}'", identity.GetType().Name)); } } ((ClassMapping) classMap).Set(x => x.Id, Layer.Defaults, identity); }
void SetDefaultAccess(Member member, IdMapping 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()); }
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); }
public void ShouldWriteTheGenerator() { var generatorMapping = new GeneratorMapping(); generatorMapping.Set(x => x.Class, Layer.Defaults, "Class"); var mapping = new IdMapping(); mapping.Set(x => x.Generator, Layer.Defaults, generatorMapping); writer.VerifyXml(mapping) .Element("generator").Exists(); }