It looks like you are missing the ID generator in your Id mapping.  you
need to tell it who or how the primary key is being generated.

you want something in your mapping like

Id(x => x.Id, map =>
{
map.Column("Id"); //this is unneccesary because you've got the same name
map.Generator(Generators.Assigned);  //or one of the values in the
Generators class
});

I'm not familiar with Firebird so much so you're going to have to play
around with them.


On Wed, May 8, 2013 at 3:53 AM, Drognan <[email protected]> wrote:

> I'm trying to map the following class structure by code, but failing
> miserabley. I'm using Firebird as my database and NHibernante 3.3.1.400.
>
> public abstract Behaviour : Entity<Long>
> {
>   public abstract Product Process(Product product);
> }
>
> public class DiscountBehaviour : Behaviour
> {
>   public virtual float Discount{ get; set; }
>   public override Product Process(Product product) { /* some logic*/ }
> }
>
> public class NewPriceBehaviour : Behaviour
> {
>   public virtual decimal NewPrice { get; set; }
>   public override Product Process(Product product) { /* some logic*/ }
> }
>
>
> This is my mapping:
>
> public class BehaviourMap : ClassMapping<Behaviour>
>     {
>         public BehaviourMap()
>         {
>             Id(x => x.Id);
>         }
>     }
>
>     public class DiscountBehaviourMap :
> JoinedSubclassMapping<DiscountBehaviour>
>     {
>         public DiscountBehaviourMap()
>         {
>             Key(k => k.Column("`BehaviourId`"));
>             Property(x => x.Discount);
>         }
>     }
>
>     public class NewPriceBehaviourMap :
> JoinedSubclassMapping<NewPriceBehaviour>
>     {
>         public NewPriceBehaviourMap()
>         {
>             Key(k => k.Column("`BehaviourId`"));
>             Property(x => x.NewPrice);
>         }
>     }
>
> My database script looks like this:
>
> CREATE TABLE ""Behaviour"" (
>   ""Id"" ""Key"" NOT NULL,
>   CONSTRAINT ""PkBehaviour"" PRIMARY KEY (""Id""));
>
> CREATE TABLE ""DiscountPricingBehaviour"" (
>   ""Id"" ""Key"" NOT NULL,
>   ""BehaviourId"" ""Key"" NOT NULL,
>   ""Discount"" FLOAT NOT NULL,
>   CONSTRAINT ""PkDiscountPricingBehaviour"" PRIMARY KEY (""Id""),
>   CONSTRAINT ""FkDPBehaviourBehaviour""
>     FOREIGN KEY (""BehaviourId"")
>     REFERENCES ""Behaviour"" (""Id""));
>
> When trying to commit this transaction I get the following error in
> Firebird:
>
> validation error for column Id, value "*** null ***"
>
> So my question is really... what am I missing here? Is there any
> documentation that might lead me in the right direction, or should I look
> in the code?
>
> Best Regards
>
>  --
> You received this message because you are subscribed to the Google Groups
> "nhusers" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/nhusers?hl=en-US.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/nhusers?hl=en-US.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to