开发者

Association references unmapped class: System.Guid

I keep getting the exception Association references unmapped class: System.Guid with NHibernate 3.1 and FluentNHibernate 1.2.

I'm not sure how this is possible. Isn't the mapping of Guid handled internally?

I saw several previous mentions of a bug in Fluent NHibernate 1.0 and someone mentioned to use trunk instead where it was fixed, but I'm on 1.2 rather than 1.0, so presumably this issue has been resolved.

Edit: Here's some additional information -- an example HBM I've exported from the Fluent AutoMapper looks like the following

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-lazy="false">
  <class xmlns="urn:nhibernate-mapping-2.2" lazy="false" name="Treadmarks.Bus.Frontend.Model.PassType, Frontend, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" table="`PassType`">
    <id name="PassTypeId" type="System.Guid, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
      <column name="PassTypeId" />
      <generator class="guid.comb" />
    </id>
    <property name="Name" type="System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
      <column name="Name" />
    </property>

    <property name="UsageInterval" type="System.TimeSpan, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
      <column name="UsageInterval" />
    </property>
  </class>
</hibernate-mapping>

And following is the FNH code that generates said HBM:

    private class AutomappingConfiguration : DefaultAutomappingConfiguration
    {
        public override bool ShouldMap(Type type)
        {
            return type.Namespace.StartsWith("Treadmarks.Bus.Frontend.Model");
        }

        public override bool IsId(FluentNHibernate.Member member)
        {
            return member.Name == member.DeclaringType.Name + "Id";
        }
    }

    public static Configuration BuildConfiguration()
    {
        return开发者_JAVA技巧 Fluently.Configure()
            .Database(SQLiteConfiguration.Standard.ConnectionString("Data Source=Treadmarks.db; Compress=true"))
            .Mappings(
                m => m.AutoMappings.Add(AutoMap.Assembly(Assembly.GetExecutingAssembly(), new AutomappingConfiguration())
                                            .Conventions.Add(
                                                DefaultLazy.Never(),
                                                LazyLoad.Never())
                         ).ExportTo("mappings.hbm"))
            .BuildConfiguration();
    }


It turns out FNH can't properly generate mapping for List<Guid> like it can for List<int>, etc. I'll report this to the FNH team.


I got this error message yesterday when wiring up Fluent on a new project. It is working now (with Guid keys) but I am not able to reproduce the error now.

The message itself conveys that it is looking for mapping configuration for System.Guid. My best guess is that it's seeing a property name that is triggering its foreign key logic and that property name is associated with a Guid.

Maybe you could add a new foreign key convention so it no longer makes those assumptions with that default logic?


You don't need to specificy the type for id mapping, or if you do specify an nhibernate type like 'Guid' see http://nhforge.org/doc/nh/en/index.html#mapping-types

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜