The Domain
Three entities and two components some ones implementing the same interface.
The mapping
- var entities = new[] { typeof(User), typeof(Email), typeof(InstantMessage) };
- var orm = new ObjectRelationalMapper();
- orm.TablePerClass(entities);
- var mapper = new Mapper(orm);
- mapper.Customize<IHasMessage>(x => x.Property(hasMessage => hasMessage.Message, pm => { pm.Type(NHibernateUtil.StringClob); pm.Lazy(true); }));
- mapper.Customize<Tweet>(x => x.Property(tweet => tweet.Message, pm => { pm.Type(NHibernateUtil.String); pm.Length(140); pm.Lazy(false); }));
- var mapping = mapper.CompileMappingFor(entities);
At line 7 you can see exception of the above rule only for the class Twett.
Where is the exception not of a convention but of the persistent representation of the property of an interface is clear, no ?
The XML
If you analyze the below XML you will see the ConfORM’s capability to understand the polymorphism.<class name="User">
<id name="Id" type="Int32">
<generator class="hilo" />
</id>
<property name="Name" />
<bag name="WelcomeMessage">
<key column="user_key" />
<composite-element class="UserWelcomeMessage">
<property name="ForDate" />
<property name="Message" type="StringClob" lazy="true" />
</composite-element>
</bag>
<bag name="Tweets">
<key column="user_key" />
<composite-element class="Tweet">
<property name="Message" type="String" length="140" />
</composite-element>
</bag>
</class>
<class name="Email">
<id name="Id" type="Int32">
<generator class="hilo" />
</id>
<property name="To" />
<property name="Cc" />
<property name="Message" type="StringClob" lazy="true" />
</class>
<class name="InstantMessage">
<id name="Id" type="Int32">
<generator class="hilo" />
</id>
<property name="To" />
<property name="Message" type="StringClob" lazy="true" />
</class>
<id name="Id" type="Int32">
<generator class="hilo" />
</id>
<property name="Name" />
<bag name="WelcomeMessage">
<key column="user_key" />
<composite-element class="UserWelcomeMessage">
<property name="ForDate" />
<property name="Message" type="StringClob" lazy="true" />
</composite-element>
</bag>
<bag name="Tweets">
<key column="user_key" />
<composite-element class="Tweet">
<property name="Message" type="String" length="140" />
</composite-element>
</bag>
</class>
<class name="Email">
<id name="Id" type="Int32">
<generator class="hilo" />
</id>
<property name="To" />
<property name="Cc" />
<property name="Message" type="StringClob" lazy="true" />
</class>
<class name="InstantMessage">
<id name="Id" type="Int32">
<generator class="hilo" />
</id>
<property name="To" />
<property name="Message" type="StringClob" lazy="true" />
</class>
Are you ConfORM ?
P.S. Now is time to work in another level of polymorphism between class-interfaces relations.
No comments:
Post a Comment