示例#1
0
        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);
        }
示例#2
0
        void SetDefaultAccess(Member member, VersionMapping 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());
            }
        }
示例#3
0
        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);
        }
 public new void UnsavedValue(string unsavedValue)
 {
     mapping.Set(x => x.UnsavedValue, layer, unsavedValue);
 }