public void Start(string prefix, MappedPropertyInfo item) { CodeFileBuilder componentBuilder = new CodeFileBuilder(); componentBuilder.Indent(5); const string subPrefix = "y."; HbmComponent component = item.HbmObject <HbmComponent>(); componentBuilder.AddLine(""); var componentBodyBuilder = new ClassMapBody(componentBuilder); foreach (var componentPart in component.Items) { componentBodyBuilder.Add(subPrefix, new MappedPropertyInfo(componentPart, item.FileName)); } _builder.StartMethod(prefix, string.Format("{0}<{1}>(x => x.{2}, y=>", FluentNHibernateNames.Component, item.ReturnType, item.Name)); _builder.AddLine("{"); _builder.AddLine(componentBuilder.ToString()); _builder.AddLine("})"); if (component.insert) { _builder.AddLine(string.Format(".{0}()", FluentNHibernateNames.Insert)); } if (component.update) { _builder.AddLine(string.Format(".{0}()", FluentNHibernateNames.Update)); } }
public ComponentMapper(HbmComponent component, System.Type componentType, IAccessorPropertyMapper accessorMapper, HbmMapping mapDoc) : base(componentType, mapDoc) { _component = component; _component.@class = componentType.GetShortClassName(mapDoc); _accessorPropertyMapper = accessorMapper; }
public ComponentMapper(HbmComponent component, Type componentType, MemberInfo declaringTypeMember, HbmMapping mapDoc) : base(componentType, mapDoc) { this.component = component; component.@class = componentType.GetShortClassName(mapDoc); accessorPropertyMapper = new AccessorPropertyMapper(declaringTypeMember.DeclaringType, declaringTypeMember.Name, x => component.access = x); }
public void WhenNoDefaultAssignComponentClassAssemblyQualifiedName() { var mapping = new HbmMapping(); var hbm = new HbmComponent(); new ComponentMapper <Address>(mapping, hbm); hbm.Class.Should().Be.EqualTo(typeof(Address).AssemblyQualifiedName); }
public void CanSetComponentAccessor() { var mapdoc = new HbmMapping(); var component = new HbmComponent(); var mapper = new ComponentMapper(component, typeof(Name), ForClass <Person> .Property(p => p.Name), mapdoc); mapper.Access(Accessor.Field); component.access.Should().Contain("field"); }
public void CanSetUpdate() { var mapdoc = new HbmMapping(); var component = new HbmComponent(); var mapper = new ComponentMapper(component, typeof(Name), ForClass <Person> .Property(p => p.Name), mapdoc); mapper.Update(false); component.update.Should().Be.False(); }
public void CanSetParentAccessor() { var mapdoc = new HbmMapping(); var component = new HbmComponent(); var mapper = new ComponentMapper(component, typeof(Name), ConfOrm.ForClass <Person> .Property(p => p.Name), mapdoc); mapper.Parent(typeof(Address).GetProperty("Parent"), pm => pm.Access(Accessor.Field)); component.Parent.access.Should().Contain("field"); }
public void CanSetLazy() { var mapdoc = new HbmMapping(); var component = new HbmComponent(); var mapper = new ComponentMapper(component, typeof(Name), ConfOrm.ForClass <Person> .Property(p => p.Name), mapdoc); mapper.Lazy(true); component.lazy.Should().Be.True(); }
public void CanSetOptimisticLock() { var mapdoc = new HbmMapping(); var component = new HbmComponent(); var mapper = new ComponentMapper(component, typeof(Name), ConfOrm.ForClass <Person> .Property(p => p.Name), mapdoc); mapper.OptimisticLock(false); component.optimisticlock.Should().Be.False(); }
public void CanSetInsert() { var mapdoc = new HbmMapping(); var component = new HbmComponent(); var mapper = new ComponentMapper(component, typeof(Name), ConfOrm.ForClass <Person> .Property(p => p.Name), mapdoc); mapper.Insert(false); component.insert.Should().Be.False(); }
public void Component(MemberInfo property, Action <IComponentMapper> mapping) { var hbm = new HbmComponent { name = property.Name }; mapping(new ComponentMapper(hbm, property.GetPropertyOrFieldType(), new NoMemberPropertyMapper(), MapDoc)); AddProperty(hbm); }
public void CanAddSimpleProperty() { var mapping = new HbmMapping(); var hbm = new HbmComponent(); var map = new ComponentMapper <Address>(mapping, hbm); map.Property(address => address.City); hbm.Items.Should().Have.Count.EqualTo(1); hbm.Items.First().Should().Be.OfType <HbmProperty>().And.ValueOf.Name.Should().Be.EqualTo("City"); }
public void WhenDefaultNamespaceAndDefaultAssemblyAssignComponentClassName() { var mapping = new HbmMapping { assembly = typeof(Address).Assembly.GetName().Name, @namespace = typeof(Address).Namespace }; var hbm = new HbmComponent(); new ComponentMapper <Address>(mapping, hbm); hbm.Class.Should().Be.EqualTo("Address"); }
public void CallingParentSetTheParentNode() { var mapdoc = new HbmMapping(); var component = new HbmComponent(); var mapper = new ComponentMapper(component, typeof(Name), ConfOrm.ForClass <Person> .Property(p => p.Name), mapdoc); mapper.Parent(typeof(Address).GetProperty("Parent")); component.Parent.Should().Not.Be.Null(); component.Parent.name.Should().Be.EqualTo("Parent"); }
public void Should_get_the_correct_value() { const string expected = "System.String"; HbmComponent component = new HbmComponent { @class = expected + ", mscorlib" }; string result = component.GetReturnType(); result.ShouldBeEqualTo(expected); }
public void Should_get_the_correct_value() { const string expected = "FirstName"; HbmComponent component = new HbmComponent { name = expected }; string result = component.GetPropertyName(); result.ShouldBeEqualTo(expected); }
public void WhenMapDocHasDefaultHasClassName() { var entityType = typeof(Person); var mapdoc = new HbmMapping { assembly = entityType.Assembly.FullName, @namespace = entityType.Namespace }; var component = new HbmComponent(); new ComponentMapper(component, typeof(Name), ConfOrm.ForClass <Person> .Property(p => p.Name), mapdoc); component.Class.Should().Be.EqualTo(typeof(Name).Name); }
public void Component <TComponent>(Expression <Func <TEntity, TComponent> > property, Action <IComponentMapper <TComponent> > mapping) where TComponent : class { var memberInfo = TypeUtils.DecodeMemberAccessExpression(property); var hbm = new HbmComponent { name = memberInfo.Name }; mapping(new ComponentMapper <TComponent>(MapDoc, hbm)); AddProperty(hbm); }
public virtual void Component(MemberInfo property, Action <IComponentMapper> mapping) { if (!IsMemberSupportedByMappedContainer(property)) { throw new ArgumentOutOfRangeException("property", "Can't add a property of another graph"); } var hbm = new HbmComponent { name = property.Name }; mapping(new ComponentMapper(hbm, property.GetPropertyOrFieldType(), property, MapDoc)); AddProperty(hbm); }
private void BindComponentProperty(HbmComponent componentMapping, Property property, Component model) { property.IsUpdateable = componentMapping.update; property.IsInsertable = componentMapping.insert; if (componentMapping.unique) { model.Owner.Table.CreateUniqueKey(model.ColumnIterator.OfType <Column>().ToList()); } HbmTuplizer[] tuplizers = componentMapping.tuplizer; if (tuplizers != null) { Array.ForEach(tuplizers.Select(tuplizer => new { TuplizerClassName = FullQualifiedClassName(tuplizer.@class, mappings), Mode = tuplizer.entitymode.ToEntityMode() }).ToArray(), x => model.AddTuplizer(x.Mode, x.TuplizerClassName)); } }
private void BindComponentProperty(HbmComponent componentMapping, Property property, Component model) { property.IsUpdateable = componentMapping.update; property.IsInsertable = componentMapping.insert; if (componentMapping.unique) { model.Owner.Table.CreateUniqueKey(model.ColumnIterator.OfType <Column>().ToList()); } HbmTuplizer[] tuplizers = componentMapping.tuplizer; if (tuplizers != null) { foreach (var tuplizer in tuplizers) { var mode = tuplizer.entitymode.ToEntityMode(); var tuplizerClassName = FullQualifiedClassName(tuplizer.@class, mappings); model.AddTuplizer(mode, tuplizerClassName); } } }
public static string GetPropertyName(this HbmComponent item) { return(item.name); }
public ComponentMapper(HbmComponent component, System.Type componentType, MemberInfo declaringTypeMember, HbmMapping mapDoc) : this(component, componentType, new AccessorPropertyMapper(declaringTypeMember.DeclaringType, declaringTypeMember.Name, x => component.access = x), mapDoc) { }
public ComponentMapper(HbmMapping mapping, HbmComponent component) : base(mapping) { this.component = component; component.@class = GetClassName(); }
public static string GetReturnType(this HbmComponent item) { return(item.@class?.GetTypeName()); }