Here is a little more detail on the compile time error I'm getting.
I went back and looked at my code again and I think I made a mistake
in my original post. I was pretty sure that it was giving a compiler
error on the actual fluent mapping, but I was wrong, Instead, it is
giving a compile time error when generating the db schema without
casting.
If I don't cast, ie.,
DiscriminateSubClassesOnColumn<ChildType>("ChildType")
.SubClass<ChildTypeA>(ChildType.ChildA, x => x.References(y =
y.ChildADetail))
.SubClass<ChildTypeB>(ChildType.ChildB, x => x.References(y =
y.ChildBDetail));
Then when I try to generate the db schema, I get the following compile
time error:
"... failed: An invalid or incomplete configuration was used while
creating a SessionFactory. Check PotentialReasons collection, and
InnerException for more detail.
NHibernate.MappingException: Could not format discriminator value to
SQL string of entity Test.Core.Parent ---> System.ArgumentException:
Requested value 'Test.Core.Parent' was not found.
at System.Enum.Parse(Type enumType, String value, Boolean ignoreCase)
at System.Enum.Parse(Type enumType, String value)
at NHibernate.Type.AbstractEnumType.StringToObject(String xml)
at NHibernate.Persister.Entity.SingleTableEntityPersister..ctor
(PersistentClass persistentClass, ICacheConcurrencyStrategy cache,
ISessionFactoryImplementor factory, IMapping mapping)
--- End of inner exception stack trace ---
at NHibernate.Persister.Entity.SingleTableEntityPersister..ctor
(PersistentClass persistentClass, ICacheConcurrencyStrategy cache,
ISessionFactoryImplementor factory, IMapping mapping)
at NHibernate.Persister.PersisterFactory.CreateClassPersister
(PersistentClass model, ICacheConcurrencyStrategy cache,
ISessionFactoryImplementor factory, IMapping cfg)
at NHibernate.Impl.SessionFactoryImpl..ctor(Configuration cfg,
IMapping mapping, Settings settings, EventListeners listeners)
at NHibernate.Cfg.Configuration.BuildSessionFactory()
at FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory()
--- End of inner exception stack trace ---
at FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory()
C:\MyStuff\Projects\SharpArchitecture\src\SharpArch\SharpArch.Data
\NHibernate\NHibernateSession.cs(0,0): at
SharpArch.Data.NHibernate.NHibernateSession.CreateSessionFactoryFor
(String[] mappingAssemblies, AutoPersistenceModel
autoPersistenceModel, Configuration cfg)
C:\MyStuff\Projects\SharpArchitecture\src\SharpArch\SharpArch.Data
\NHibernate\NHibernateSession.cs(67,0): at
SharpArch.Data.NHibernate.NHibernateSession.Init(ISessionStorage
storage, String[] mappingAssemblies, AutoPersistenceModel
autoPersistenceModel, String cfgFile, IDictionary`2 cfgProperties,
String validatorCfgFile)
C:\MyStuff\Projects\SharpArchitecture\src\SharpArch\SharpArch.Data
\NHibernate\NHibernateSession.cs(29,0): at
SharpArch.Data.NHibernate.NHibernateSession.Init(ISessionStorage
storage, String[] mappingAssemblies, String cfgFile)
C:\dev\<snipped>\DatabaseMaintenance.cs(21,0): at
Tests.<snipped>.ShowMeTheDDLForTheDatabaseBasedOnFluentNHibernateMappings
()
* Database was not configured through Database method.
Hope that helps.
todd
On May 28, 2:52 am, James Gregory <[email protected]> wrote:
> It definitely shouldn't fail if you don't cast it, that's a bug. We're still
> not entirely decided on what the default behavior should be for enums, some
> say they should be stored as strings, others as ints. Either way though, it
> should default to one of them!
>
> I've created an
> issue<http://code.google.com/p/fluent-nhibernate/issues/detail?id=240>that
> you can track.
>
> On Thu, May 28, 2009 at 8:02 AM, todd brooks <[email protected]> wrote:
>
> > This works, but I would like to make sure I'm using the correct
> > syntax, as (in my naive opinion), it seems "wordy".
>
> > I have a Parent class. it is discriminated based on an enum:
>
> > public enum ChildType
> > {
> > ChildA = 0,
> > ChildB = 1
> > }
>
> > In my Parent mapping, I have this:
>
> > DiscriminateSubClassesOnColumn("ChildType", (int)ChildType.ChildA)
> > .SubClass<ChildTypeA>((int)ChildType.ChildA, x => x.References(y
> > = y.ChildADetail))
> > .SubClass<ChildTypeB>((int)ChildType.ChildB, x => x.References(y
> > = y.ChildBDetail));
>
> > Should I be casting the enums to int? It seems redundant to me, but
> > if I don't, it won't compile.
>
> > I would think that it should look like this:
>
> > DiscriminateSubClassesOnColumn<ChildType>("ChildType")
> > .SubClass<ChildTypeA>(ChildType.ChildA, x => x.References(y =
> > y.ChildADetail))
> > .SubClass<ChildTypeB>(ChildType.ChildB, x => x.References(y =
> > y.ChildBDetail));
>
> > It would seem to me that Fluent should be able to determine the
> > datatype of the enum.
>
> > Am I missing something obvious? Am I doing it correctly?
>
> > Many thanks in advance.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Fluent NHibernate" 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/fluent-nhibernate?hl=en
-~----------~----~----~----~------~----~------~--~---