Inheritance: MappingBase, IIdentityMapping
        public void SettingNameShouldSetMappedToTrue()
        {
            var mapping = new CompositeIdMapping();

            mapping.Set(x => x.Name, Layer.Defaults, "someName");
            mapping.Mapped.ShouldBeTrue();
        }
        public void CanSetIdToBeCompositeIdMapping()
        {
            var idMapping = new CompositeIdMapping();
            _classMapping.Id = idMapping;

            _classMapping.Id.ShouldEqual(idMapping);
        }
        public void SettingNameShouldSetMappedToTrue()
        {
            var mapping = new CompositeIdMapping();

            mapping.Name = "someName";
            mapping.Mapped.ShouldBeTrue();
        }
        public void CanSetIdToBeCompositeIdMapping()
        {
            var idMapping = new CompositeIdMapping();
            mapping.Set(x => x.Id, Layer.Defaults, idMapping);

            mapping.Id.ShouldEqual(idMapping);
        }
        public void SettingNameToBlankValueShouldSetMappedToFalse()
        {
            var mapping = new CompositeIdMapping();
            mapping.Mapped = true;

            mapping.Name = null;
            mapping.Mapped.ShouldBeFalse();
        }
        public void MappedShouldDefaultToFalseIfNameAttributeIsBlank()
        {
            var store = new AttributeStore<CompositeIdMapping>();
            store.Set(x => x.Name, string.Empty);

            var mapping = new CompositeIdMapping(store.CloneInner());
            mapping.Mapped.ShouldBeFalse();
        }
        public void MappedShouldDefaultToTrueIfNameAttributeIsSet()
        {
            var store = new AttributeStore<CompositeIdMapping>();
            store.Set(x => x.Name, "someName");

            var mapping = new CompositeIdMapping(store.CloneInner());
            mapping.Mapped.ShouldBeTrue();
        }
        public void ShouldWriteKeyProperties()
        {
            var mapping = new CompositeIdMapping();

            mapping.AddKeyProperty(new KeyPropertyMapping());

            writer.VerifyXml(mapping)
                .Element("key-property").Exists();
        }
        public void ShouldWriteKeyManyToOnes()
        {
            var mapping = new CompositeIdMapping();

            mapping.AddKeyManyToOne(new KeyManyToOneMapping());

            writer.VerifyXml(mapping)
                .Element("key-many-to-one").Exists();
        }
Beispiel #10
0
        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);
        }
 public void CreateDsl()
 {
     mapping = new CompositeIdMapping();
     inspector = new CompositeIdentityInspector(mapping);
 }
 public CompositeIdentityInspector(CompositeIdMapping mapping)
 {
     this.mapping = mapping;
 }
 public override void ProcessCompositeId(CompositeIdMapping idMapping)
 {
     ProcessIdentity(idMapping);
 }
 public void MappedShouldDefaultToFalseOnDefaultConstructor()
 {
     var mapping = new CompositeIdMapping();
     mapping.Mapped.ShouldBeFalse();
 }
 public void SettingNameToBlankValueShouldSetMappedToFalse()
 {
     var mapping = new CompositeIdMapping();
     mapping.Set(x => x.Name, Layer.Defaults, null);
     mapping.Mapped.ShouldBeFalse();
 }
 public CompositeIdentityInstance(CompositeIdMapping mapping)
     : base(mapping)
 {
     this.mapping = mapping;
 }
 public void UnsavedValueShouldDefaultToUndefined()
 {
     var mapping = new CompositeIdMapping();
     mapping.UnsavedValue.ShouldEqual("undefined");
 }
 public virtual void ProcessCompositeId(CompositeIdMapping idMapping)
 {
 }
 public CompositeIdentityInspector(CompositeIdMapping mapping)
 {
     this.mapping = mapping;
     mappedProperties.AutoMap();
 }