질문의 게터를 발생NHibernate에 : 예외
예외가 nhDBapi.DB.Tables.clsSettings의 게터 발생 : 나는 데이터베이스에 clsSettings의 인스턴스를 삽입하려고 할 때이 NHibernate에 오류가 발생하는 것을 계속한다. UID
이 예외 때문에 클래스 아래의 모든 메서드가 작동하지 않습니다.
재미있는 점은 모든 것이 nhDBapi.exe라는 실행 파일에있을 때 작동하며 dll에 있어도 테이블 스키마가 올바르게 만들어집니다. 내가 MailServer.exe에 의해로드 API_nHibernate.dll에 동일한 코드를 이동하면
, 다음 작동이 중지 ...
는 둘 사이의 유일한 차이점은 EXE에, 내가 사용
[NHibernate.Mapping.Attributes.Class(Name = "nhDBapi.DB.Tables.clsSettings, nhDBapi", Table = "T_lsSettings")]
DLL에있는
동안 제가 사용
[NHibernate.Mapping.Attributes.Class(Name = "nhDBapi.DB.Tables.clsSettings, API_nHibernate", Table = "T_lsSettings")]
은 정확해야한다. 다음은 클래스
:using System;
using System.Collections.Generic;
using System.Text;
namespace nhDBapi.DB.Tables
{
[NHibernate.Mapping.Attributes.Class(Name = "nhDBapi.DB.Tables.clsSettings, API_nHibernate", Table = "T_lsSettings")]
public class clsSettings
{
[NHibernate.Mapping.Attributes.Id(Name = "UID", Column = "S_UID", TypeType = typeof(System.Guid))]
public virtual System.Guid UID
{
get { return m_UID; }
set { m_UID = value; }
} // UserID
protected System.Guid m_UID;
[NHibernate.Mapping.Attributes.Property(Name = "Settings", Column = "S_Settings", TypeType = typeof(System.Byte[]))]
public virtual System.Byte[] Settings
{
get { return m_Settings; }
set { m_Settings = value; }
} // UserID
protected System.Byte[] m_Settings;
} // End partial class lsSettings
} // End Namespace nhDBapi.DB.Tables
그리고 여기에 모든 삽입 방법은 내가 시도 :
// nhDBapi.DBaccess.Insert<nhDBapi.DB.Tables.clsDomains>(x);
public static void InsertRef<T>(ref T RowToAdd)
{
/*
List<T> lsRows = new List<T>();
lsRows.Add(RowToAdd);
Insert<T>(lsRows);
lsRows.Clear();
lsRows = null;
*/
NHibernate.ISession session = m_bsfSessionFactory.OpenSession();
NHibernate.ITransaction transaction = session.BeginTransaction();
session.SaveOrUpdate(RowToAdd);
transaction.Commit();
session.Close();
transaction.Dispose();
session.Dispose();
} // End Sub Insert
// nhDBapi.DBaccess.Insert<nhDBapi.DB.Tables.clsDomains>(x);
public static void Insert<T>(T RowToAdd)
{
/*
List<T> lsRows = new List<T>();
lsRows.Add(RowToAdd);
Insert<T>(lsRows);
lsRows.Clear();
lsRows = null;
*/
NHibernate.ISession session = m_bsfSessionFactory.OpenSession();
NHibernate.ITransaction transaction = session.BeginTransaction();
session.SaveOrUpdate(RowToAdd);
transaction.Commit();
session.Close();
transaction.Dispose();
session.Dispose();
} // End Sub Insert
// nhDBapi.DBaccess.Insert<nhDBapi.DB.Tables.clsDomains>(xx);
public static void Insert<T>(List<T> ListOfRowsToAdd)
{
NHibernate.ISession session = m_bsfSessionFactory.OpenSession();
NHibernate.ITransaction transaction = session.BeginTransaction();
// Tell NHibernate that this object should be saved
// commit all of the changes to the DB and close the ISession
try
{
for (int i = 0; i < ListOfRowsToAdd.Count; ++i)
{
session.SaveOrUpdate(ListOfRowsToAdd[i]);
}
/*
foreach (T tThisRow in ListOfRowsToAdd)
{
// session.Save(tThisRow);
session.SaveOrUpdate(tThisRow);
} // Next tThisRow
*/
transaction.Commit();
session.Close();
transaction.Dispose();
session.Dispose();
} // End try
catch (Exception ex)
{
MsgBox(ex.Message, "Error");
//Console.WriteLine(ex.InnerException.Message);
System.Environment.Exit(1);
} // End catch
} // End Sub Insert
어셈블리 이름을 제거하면 예외가 발생합니다. Nhibernate.MappingException : Persistent class nhDBapi.DB.Tables.clsIMAP_ACL not found. 가능한 원인 : 어셈블리 이름을 지정하지 않았습니다. 적어도 어셈블리를 지정하면 테이블 생성이 제대로 작동합니다. –
@Quandary : Name 속성을 정의하는 특별한 이유는 무엇입니까? 내가 NHibernate가 당신을 위해 그것을 추론 할 것이라고 말했다. –
아니요. 필요하지 않다면 좋겠지 만 어셈블리 이름을 제공하지 않으면 cfg에 매핑을 추가하려고 할 때 예외가 발생합니다. –