It looks like same problem occurs with the length attribute. As with
the previous fix, when the column element is present in a property, as
it is the FNH hbm exports, the length should be on the column instead
of the property.


On Feb 19, 11:23 am, Steven Lyons <stevenly...@gmail.com> wrote:
> Hi James,
>
> The new fix has partly resolved the issue. The "not null" is now
> making it through to the schema but the unique constraint is still
> being dropped.
>
> s.
>
> On Feb 19, 9:35 am, James Gregory <jagregory....@gmail.com> wrote:
>
> > There was a bug in the Not.Nullable code that I've just fixed, could you
> > confirm (or deny) whether this has had any affect on your problem?
>
> > On Thu, Feb 19, 2009 at 12:09 AM, Steven Lyons <stevenly...@gmail.com>wrote:
>
> > > Hi All,
>
> > > I'm having a weird problem that hopefully someone might have some
> > > thoughts about.
>
> > > I am trying to auto map and assign more specific constraints to a type
> > > (see User in code below). This is mostly just basic code I've gotten
> > > from blogs. When I run my test, the hbm export file is created and has
> > > the correct attributes. However, the the SchemaExport output to the
> > > console is missing the unique constraint and non-null specification.
>
> > > The strange part is that is if I use the hbm mappings in the
> > > BuildSessionFactory method (currently commented out) the constraints
> > > are added to the schema. It's when I try to use the auto mapping that
> > > I run into trouble. I also had this working previously (using the non-
> > > fluent configuration, see below) but that code also stopped working
> > > with the same problem when I updated to a recent FNH version.
>
> > > Is this something that I was doing wrong before and just happened to
> > > work? Or is this a regression?
>
> > > Thanks!
> > > s.
>
> > > -------
>
> > > // Create SessionFactory
> > > UnitOfWork.SessionFactory = new NHibernateHelper().BuildSessionFactory
> > > (config, BuildSchema);
>
> > > // Export Schema
> > > public void BuildSchema(Configuration cfg)
> > > {
> > >    new SchemaExport(cfg).Create(true, true);
> > > }
>
> > > // Build Session Factory
> > > public ISessionFactory BuildSessionFactory(Configuration config,
> > >                                           Action<Configuration>
> > > configAction)
> > > {
> > >    var f = FluentNHibernate.Cfg.Fluently
> > >        .Configure(config)
> > >        .Mappings(m =>
> > >        {
> > >            //m.HbmMappings
> > >            // .AddFromAssemblyOf<NHibernateHelper>();
>
> > >            m.AutoMappings.Add(
> > >                AutoPersistenceModel.MapEntitiesFromAssemblyOf<IEntity>
> > > ()
> > >                    .Where(entity => entity.Namespace.Contains
> > > ("Domain") &&
> > >                                     entity.GetProperty("Id") != null
> > > &&
> > >                                     entity.IsAbstract == false)
> > >                    .WithConvention(convention =>
> > >                    {
> > >                        convention.IsBaseType = (type => (type ==
> > > typeof(Entity<int>) ||
> > >                                                         (type ==
> > > typeof(Entity<Guid>))));
> > >                    })
> > >                    .ForTypesThatDeriveFrom<User>(map =>
> > >                    {
> > >                        map.Map(p => p.Username).Unique().Not.Nullable
> > > ();
> > >                    })
> > >            ).ExportTo(@"c:\src\project\log\");
> > >        })
> > >        .ExposeConfiguration(configAction)
> > >        .BuildSessionFactory();
>
> > >    return f;
> > > }
>
> > > <!-- hbm Export File -->
> > > <?xml version="1.0" encoding="utf-8" ?>
> > > <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-
> > > lazy="true" assembly="Project.Core" namespace="Project.Core.Domain">
> > >  <class name="User" table="Users" xmlns="urn:nhibernate-mapping-2.2">
> > >  <id name="Id" column="Id" type="Guid">
> > >    <generator class="guid.comb" />
> > >  </id>
> > >    <property name="Username" unique="true" not-null="true"
> > > length="100" type="String">
> > >      <column name="Username" />
> > >    </property>
> > >  </class>
> > > </hibernate-mapping>
>
> > > -- SQLite schema export:
> > > create table Users (
> > >  Id UNIQUEIDENTIFIER not null,
> > >   Username TEXT,
> > >   primary key (Id)
> > > )
>
> > > // Previously working code
> > > public PersistenceModel BuildModel()
> > > {
> > >    var model = new AutoPersistenceModel();
>
> > >    foreach (Assembly assembly in this.fluentAssemblies)
> > >    {
> > >        // Add assembly for the fluent mapping files
> > >        model.addMappingsFromAssembly(assembly);
>
> > >        // Add assembly and configuration for fluent AutoMapped
> > > classes
> > >        model.AddEntityAssembly(assembly);
> > >    }
>
> > >    model.Where(entity => entity.Namespace.Contains("Domain") &&
> > >                          entity.GetProperty("Id") != null &&
> > >                          entity.IsAbstract == false)
> > >         .WithConvention(c =>
> > >          {
> > >              c.IsBaseType = (type => (type == typeof(Entity<int>) ||
> > >                                      (type == typeof
> > > (Entity<Guid>))));
> > >         });
>
> > >    // TODO: Move these out to a proper location!!!
> > >    model.ForTypesThatDeriveFrom<User>(map =>
> > >    {
> > >        map.Map(p => p.Username).WithUniqueConstraint()
> > >                               .CanNotBeNull();
> > >    });
>
> > >    return model;
> > > }
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Fluent NHibernate" group.
To post to this group, send email to fluent-nhibernate@googlegroups.com
To unsubscribe from this group, send email to 
fluent-nhibernate+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/fluent-nhibernate?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to