流畅的NHibernate异常:表X中的关联引用了未映射的类:System.String

时间:2014-09-19 09:53:39

标签: c# nhibernate oracle11g fluent-nhibernate

我正在尝试将11g中的oracle表映射到此类:

public class AdminTest
{
    public virtual int Id { get; set; }
    public virtual string PlayerName { get; set; }
    public virtual string ClassYear { get; set; }
    public virtual char IsMinor { get; set; }
    public virtual char HasPaid { get; set; }
    public virtual string Sport { get; set; }
    public virtual string YearRegistered{ get; set; }
    public virtual string SemesterChooseSport { get; set; }
    public virtual char IsCaptain { get; set; }
    public virtual string PlayerBuUsername { get; set; }
}

和这个流畅的映射:

public class AdminTestMap: ClassMap<AdminTest>
    {
        public AdminTestMap()
        {
            //id is the primary key of the table
            Table("tbl_117_admintest");
            Id(x => x.Id).GeneratedBy.Sequence("seq_117_admintest");
            References(x=>x.PlayerName).Column("player_name");
            References(x=>x.ClassYear).Column("class_year");
            References(x=>x.IsMinor).Column("isMinor");
            References(x=>x.HasPaid).Column("hasPaid");
            References(x=>x.Sport).Column("sport");
            References(x=>x.YearRegistered).Column("year_registered");
            References(x=>x.SemesterChooseSport).Column("semester_choose_sport");
            References(x=>x.IsCaptain).Column("isCaptain");
            References(x=>x.PlayerBuUsername).Column("playerBUUsername");
        }
    }

使用此配置:         public static ISessionFactory CreateSessionFactory()         {

        var cfg = OracleClientConfiguration.Oracle10
            .ConnectionString(c =>
                c.Is("connstr"));

        return Fluently.Configure()
                .Database(cfg)
                .Mappings(m => m.FluentMappings.AddFromAssemblyOf<Program>().ExportTo(@".\"))
                .ExposeConfiguration(BuildSchema)
        .BuildSessionFactory();
    }

我已经查看了这三个链接以寻求帮助: http://www.patternwebsolutions.com/2011/07/10/connect-to-oracle-using-fluentnhibernate/ Fluent NHibernate 3 and Oracle.DataAccess http://www.nullskull.com/q/10226070/fluent-nhibernate-configuration-for-oracle-11g.aspx

我没有运气消除上面的异常:来自表tbl_117_admintest的关联引用了一个未映射的类:System.String。我在VS13中引用了Oracle.DataAccess.dll。 任何方向将不胜感激。

1 个答案:

答案 0 :(得分:4)

我没有使用过流利的nhibernate,但提示似乎是系统告诉你它无法找到地图的类。

您永远不会映射字符串类。我认为问题是你正在使用

引用(x =&gt; x.PlayerName)来映射所有属性,尝试使用Map(x =&gt; x.PlayerName)代替。