Same domain
var mapper = new ModelMapper();
mapper.Class<Activity>(c =>
{
c.DiscriminatorValue(0);
c.Discriminator(map =>
{
map.Column("DISCRIMINATOR_TYPE");
map.Type(NHibernateUtil.Int32);
map.NotNullable(true);
});
c.Id(x => x.Id, map => map.Generator(Generators.Guid));
c.Property(x => x.Title);
});
mapper.Subclass<FormActivity>(c =>
{
c.DiscriminatorValue((int)ActivityType.Form);
});
Mapping:
<class name="Activity" discriminator-value="0">
<id name="Id" type="Guid">
<generator class="guid" />
</id>
<discriminator column="DISCRIMINATOR_TYPE" type="Int32" />
<property name="Title" />
</class>
<subclass name="FormActivity" discriminator-value="1" extends="Activity" />
On Wed, May 4, 2011 at 9:15 AM, Fabio Maulo <[email protected]> wrote:
> private class Entity
> {
> public Guid Id { get; set; }
> }
> private class Activity: Entity
> {
> public string Title { get; set; }
> }
>
> private class FormActivity:Activity
> {
> }
> public enum ActivityType
> {
> Form = 1,
> Custom = 2,
> Email = 3
> }
> [Test]
> public void WhenMapDiscriminatorValueThenNotThrows()
> {
> var mapper = new ModelMapper();
> mapper.Class<Activity>(c =>
> {
> c.DiscriminatorValue(0);
> c.Id(x => x.Id, map => map.Generator(Generators.Guid));
> c.Property(x => x.Title);
> });
> mapper.Subclass<FormActivity>(c =>
> {
> c.DiscriminatorValue((int)ActivityType.Form);
> });
>
> Console.WriteLine(mapper.CompileMappingForAllExplicitAddedEntities().AsString());
> }
>
> Mapping:
> <class name="Activity" discriminator-value="0">
> <id name="Id" type="Guid">
> <generator class="guid" />
> </id>
> <discriminator type="Int32" />
> <property name="Title" />
> </class>
>
> <subclass name="FormActivity" discriminator-value="1" extends="Activity" />
>
> Can you send me the same thing I'm sending you but generating the exception
> you are seeing ?
> Thanks
>
> On Wed, May 4, 2011 at 8:39 AM, Luka <[email protected]> wrote:
>
>> public enum ActivityType
>> {
>> Form = 1,
>> Custom = 2,
>> Email = 3
>> }
>>
>> I tried to change:
>> mapper.Subclass<FormActivity>(map=>map.DiscriminatorValue( 1 )); , but
>> with the same error
>>
>>
>> On May 4, 1:23 pm, Fabio Maulo <[email protected]> wrote:
>> > what is ActivityType ?
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> > On Wed, May 4, 2011 at 8:17 AM, Luka <[email protected]> wrote:
>> > > hi, Fabio
>> >
>> > > I have corrected my scenario like this:
>> > > mapper.Class<Activity>(map =>
>> > > {
>> > > map.Discriminator(dm =>
>> > > {
>> >
>> > > dm.Column("DISCRIMINATOR_TYPE");
>> >
>> > > dm.Type(typeof(System.Int32));
>> > > dm.NotNullable(true);
>> > > });
>> > > });
>> > >
>> mapper.Subclass<FormActivity>(map=>map.DiscriminatorValue(ActivityType.Form
>> > > ));
>> >
>> > > Now discriminator is not a Property anymore. But I get same error.
>> >
>> > > On May 4, 12:59 pm, Fabio Maulo <[email protected]> wrote:
>> > > > The discriminator *can't* be a property.
>> >
>> > > > On Wed, May 4, 2011 at 6:18 AM, Luka <[email protected]> wrote:
>> > > > > Hi,
>> > > > > I have this scenarion:
>> >
>> > > > > A table:
>> >
>> > > > > Activity
>> > > > > .Id : Guid
>> > > > > .Type: int
>> > > > > .Title: nvarchar(20)
>> > > > > ...
>> >
>> > > > > Classes
>> > > > > public class Activity: Entity
>> > > > > {
>> > > > > public virtual ActivityType Type {get;set;}
>> > > > > public virtual string Title {get;set;}
>> > > > > }
>> >
>> > > > > public class FormActivity: Activity
>> > > > > {
>> >
>> > > > > }
>> >
>> > > > > and a mapping:
>> > > > > mapper.Class<Activity>(map =>
>> > > > > {
>> >
>> > > > > map.Discriminator(dm=>dm.Column("TYPE"));
>> > > > > });
>> >
>> > >
>> mapper.Subclass<FormActivity>(map=>map.DiscriminatorValue(ActivityType.Form
>> > > ));
>> >
>> > > > > When building SessionFactory I get Exception
>> >
>> > > > > System.InvalidOperationException: Sequence contains more than one
>> > > > > matching element
>> > > > > It throws when get on this line:
>> >
>> > >
>> mapper.Subclass<FormActivity>(map=>map.DiscriminatorValue(ActivityType.Form
>> > > ));
>> >
>> > > > > what am I doing wrong?
>> >
>> > > > > --
>> > > > > You received this message because you are subscribed to the Google
>> > > Groups
>> > > > > "nhusers" group.
>> > > > > To post to this group, send email to [email protected].
>> > > > > To unsubscribe from this group, send email to
>> > > > > [email protected].
>> > > > > For more options, visit this group at
>> > > > >http://groups.google.com/group/nhusers?hl=en.
>> >
>> > > > --
>> > > > Fabio Maulo
>> >
>> > > --
>> > > You received this message because you are subscribed to the Google
>> Groups
>> > > "nhusers" group.
>> > > To post to this group, send email to [email protected].
>> > > To unsubscribe from this group, send email to
>> > > [email protected].
>> > > For more options, visit this group at
>> > >http://groups.google.com/group/nhusers?hl=en.
>> >
>> > --
>> > Fabio Maulo
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "nhusers" group.
>> To post to this group, send email to [email protected].
>> To unsubscribe from this group, send email to
>> [email protected].
>> For more options, visit this group at
>> http://groups.google.com/group/nhusers?hl=en.
>>
>>
>
>
> --
> Fabio Maulo
>
>
--
Fabio Maulo
--
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/nhusers?hl=en.