引用 NHibernate 时出错(从 'NHibernate.Dialect.Oracle10gDialect' 上的 'IdentitySelectString' 获取值时出错。)

Error in References NHibernate (Error getting value from 'IdentitySelectString' on 'NHibernate.Dialect.Oracle10gDialect'.)

我在从数据库序列化实体时遇到问题。

项目包含 2 个 classes: 通知

public class Notification:Entity
{
    public virtual string Title { get; set; }
    public virtual string Text { get; set; }
    public virtual int ToUser { get; set; }
    public virtual int FromUser { get; set; }
    public virtual DateTime Date { get; set; }
    public virtual bool Readed { get; set; }
    public virtual NotificationType Type { get; set; }
    public virtual int DocId { get; set; }
}

和通知类型

 public class NotificationType:Entity
{
    public virtual string Name { get; set; }
}

其中实体 class 是

public abstract class Entity
{
    public virtual int Id { get; set; }
}

现在我将使用 Fluent NHibernate 将其映射到 Oracle DB

 public class NotificationMap:ClassMap<Notification>
{
    public NotificationMap()
    {
        Table("NOTIFICATIONS");
        Id(x => x.Id).Column("NOTIFY_ID").Not.Nullable().GeneratedBy.Custom<NHibernate.Id.TriggerIdentityGenerator>(); ;
        Map(x => x.Title).Length(255).Column("TITLE").Nullable().CustomType("AnsiString");
        Map(x => x.Text).Length(255).Column("TEXT").Nullable().CustomType("AnsiString");
        Map(x => x.ToUser).Column("TOUSER_ID").Nullable();
        Map(x => x.FromUser).Column("USER_ID").Nullable();
        Map(x => x.Date).Column("NOTIFY_DATE").Nullable();
        Map(x => x.DocId).Column("TODOC_ID").Nullable();
        Map(x => x.Readed).Column("ISREADED").Nullable();
        References(x => x.Type, "NOTIFY_TYPE").ReadOnly();//.Cascade.None();
    }
}
public class NotificationTypeMap : ClassMap<NotificationType>
{
    public NotificationTypeMap()
    {
        Table("NOTIFICATIONS_TYPE_LIST");
        Id(x => x.Id).Column("NOTIFY_TYPE_ID").Not.Nullable();//.GeneratedBy.Custom<NHibernate.Id.TriggerIdentityGenerator>();
        Map(x => x.Name).CustomType("AnsiString").Length(255).Column("TITLE").Nullable();
    }
}

NHib 配置为

public static void Configure(string connection)
    {

        _config = Fluently
            .Configure()
            .Database(OracleClientConfiguration
                          .Oracle10
                          .ShowSql()
                          .ConnectionString(connection)
            )
            .Mappings(configuration =>
                      configuration.FluentMappings.AddFromAssemblyOf<DCMap>())
            .ExposeConfiguration(x =>
                                 x.SetInterceptor(new SqlStatementInterceptor()));

               //Build Session factory using configuration
        _sessionFactory = _config.BuildSessionFactory();
    }

要创建数据库表,您可以使用生成的 SQL 脚本

CREATE TABLE NOTIFICATIONS_TYPE_LIST
(
  NOTIFY_TYPE_ID  INTEGER                       NOT NULL,
  TITLE           VARCHAR2(250 BYTE)
)

CREATE TABLE NOTIFICATIONS
(
  NOTIFY_ID    INTEGER                          NOT NULL,
  USER_ID      INTEGER,
  TOUSER_ID    INTEGER,
  NOTIFY_TYPE  INTEGER,
  TITLE        VARCHAR2(250 BYTE),
  TEXT         VARCHAR2(250 BYTE),
  NOTIFY_DATE  DATE,
  TODOC_ID     INTEGER,
  ISREADED     INTEGER,
  ISDELETED    INTEGER
)

并创建 table 条身份触发通知。

现在,我在我的程序中提取数据:

        IEnumerable<Notification> res;
        using (var unit = UnitOfWork.Create(_dbsession))
        {
            var nRepo = unit.GetRepository<Notification>();
            res = nRepo.GetAllWhere(x=>x.ToUser==User.Id);
            //res is contain list of notification with references types.
        }
        //follow string generate (Error getting value from 'IdentitySelectString' on 'NHibernate.Dialect.Oracle10gDialect'.)
        string json = Newtonsoft.Json.JsonConvert.SerializeObject(res);

在结果中我捕获了异常"Error getting value from 'IdentitySelectString' on 'NHibernate.Dialect.Oracle10gDialect'."

问题是什么?谢谢。

我通过将映射更改为

解决了我的问题
 References(x => x.Type, "NOTIFY_TYPE").ReadOnly().Not.LazyLoad();