2012-04-17 4 views
0

DB 채우기에이 코드가 있지만 완료 후에 DB가 여전히 비어 있습니다. hibernate_unique_key 테이블의 숫자 만 더 높습니다.SharpArch.Data.NHibernate.Repository.SaveOrUpdate() 저장 안 함

다음으로 재미있는 점은 인스턴스를 디버깅하는 동안 ID가 저장되고 1,2,3 ...과 유사하지만 60083, 60084 ... 등과 같이 매우 높다는 것입니다. 저장에는 여러 행만 있기 때문에 정상입니다.

그 전에는 참조 등에서 몇 가지 문제가 있었지만 지금은 오류 메시지 나 예외가 없습니다.

코드가있다 :

using System; 
using NHibernate.Cfg; 
using SharpArch.Data.NHibernate; 
using LaboratorniMetody.Data.NHibernateMaps; 
using SharpArch.Core.PersistenceSupport; 
using LaboratorniMetody.Core; 

namespace LaboratorniMetody.FillSchema 
{ 
    class Program 
    { 
     private static Configuration configuration; 

     static void Main(string[] args) 
     { 
      configuration = NHibernateSession.Init(new SimpleSessionStorage(), new String[] { "LaboratorniMetody.Data" }, 
              new AutoPersistenceModelGenerator().Generate(), 
              "../../../../app/LaboratorniMetody.Web/NHibernate.config"); 

      IRepository<Laboratory> LaboratoryRepository = new Repository<Laboratory>(); 
      Laboratory Laboratory1 = new Laboratory() { Name = "Hematologie" };//Method 
      Laboratory l = LaboratoryRepository.SaveOrUpdate(Laboratory1); 
      Laboratory Laboratory2 = new Laboratory() { Name = "Patologie" };//Method 
      LaboratoryRepository.SaveOrUpdate(Laboratory2); 
      Laboratory Laboratory3 = new Laboratory() { Name = "Laboratoře" };//Method 
      LaboratoryRepository.SaveOrUpdate(Laboratory3); 
     } 
    } 
} 

내가 Project.Core 클래스에서 NUnit를하여 genereted DB 스키마를 사용합니다.

어디서 문제를 찾을 수 있습니까? 나는 문제없이 일하는 2 개의 매우 유사한 프로젝트를 가지고있다. 나는이 코드 중 하나에서이 코드를 복사했으며 DB 모델을 제외하고 전혀 다른 점이 없다.

답변

1

트랜잭션에서 변경을 수행 한 후 트랜잭션을 커밋해야한다.

using(var tx = NHibernateSession.Current.BeginTransaction()) 
{ 
    IRepository<Laboratory> LaboratoryRepository = new Repository<Laboratory>(); 
    Laboratory Laboratory1 = new Laboratory() { Name = "Hematologie" };//Method 
    Laboratory l = LaboratoryRepository.SaveOrUpdate(Laboratory1); 
    Laboratory Laboratory2 = new Laboratory() { Name = "Patologie" };//Method 
    LaboratoryRepository.SaveOrUpdate(Laboratory2); 
    Laboratory Laboratory3 = new Laboratory() { Name = "Laboratoře" };//Method 
    LaboratoryRepository.SaveOrUpdate(Laboratory3); 

    tx.Commit(); 
} 

나는 윈도우 응용 프로그램/서비스 SharpArch를 사용하는 방법을 사용하는 트랜잭션 거기에서 속성에 대한 몇 가지 샘플을 가지고 SharpArchContrib 프로젝트 위키,보고 조언한다.

https://github.com/sharparchitecture/Sharp-Architecture-Contrib/wiki/

+0

최고입니다. 하지만 이전 구버전에서 오래된 코드가 작동하고 새로운 코드에서 작동하지 않는 이유는 여전히 남아 있습니다. –

+0

이전 코드와 새 코드의 차이점은 무엇입니까? 그것이 문제를 해결하는 데 도움이된다면 대답을 upvote하십시오. –