The default property is only for creating the schema script. In order to
have this default in your objects, please use a backing field initialized to
the desired value.

-Markus

2009/7/27 William Chang <[email protected]>

>
> Please help? I added a "Default" attribute to my class' properties and
> the generated SQL create script is correct. When I do a insert (using
> the Save() method), I think ActiveRecord doesn't use the default
> values. Thus, give me an error:
>
> NHibernate.PropertyValueException : not-null property references a
> null or transient value
> Testsoft.Data.Models.UserProfile.userNameMiddle
>
> SQL Create Script:
>    create table UserProfiles (
>        userId VARCHAR(40) not null,
>       userNameSalutation VARCHAR(32) default ''  not null,
>       userNameMiddle VARCHAR(64) default ''  not null,
>       userOccupation VARCHAR(128) default ''  not null,
>       primary key (userId)
>    );
>
> I'm using empty string in single quotes. The source code:
> namespace Testsoft.Data.Models {
>
> [ActiveRecord("UserProfiles")]
> public class UserProfile : ActiveRecordBase<UserProfile> {
>    [PrimaryKey(PrimaryKeyType.Foreign)]
>    public virtual Guid userId {get;set;}
>
>    [Property(Length = 32, NotNull = true, Default = "''")]
>    public virtual String userNameSalutation {get;set;}
>
>    [Property(Length = 64, NotNull = true, Default = "''")]
>    public virtual String userNameMiddle {get;set;}
>
>    [Property(Length = 128, NotNull = true, Default = "''")]
>    public virtual String userOccupation {get;set;}
>
>    [OneToOne]
>    public virtual User userBase {get;set;}
> }
>
> } // END namespace Testsoft.Data.Models
>
> Executing Source Code:
> Data.Models.UserProfile obj2;
> obj2 = new Vendorsoft.Data.Models.UserProfile {
>        userBase = obj1,
>        userNameSalutation = "Mr",
>        userOccupation = "Developer"
> };
> obj2.Create();
>
> Thanks,
> William Chang
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Castle Project Users" 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/castle-project-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to