SharpArch.Data.NHibernate.Repository.SaveOrUpdate()don';救不了

SharpArch.Data.NHibernate.Repository.SaveOrUpdate()don';救不了,nhibernate,fluent-nhibernate,s#arp-architecture,Nhibernate,Fluent Nhibernate,S#arp Architecture,我有这个填充数据库的代码,但完成后,数据库仍然是空的。只有hibernate_unique_key表中的数字更高 接下来有趣的是,在调试过程中,实例在保存后具有id,但与1,2,3不同。。。但是非常高,比如60083,60084。。。等等(这似乎不正常,因为只有几行要保存) 在此之前,引用等方面存在一些问题,但现在没有错误消息或异常 代码如下: using System; using NHibernate.Cfg; using SharpArch.Data.NHibernate; using L

我有这个填充数据库的代码,但完成后,数据库仍然是空的。只有hibernate_unique_key表中的数字更高

接下来有趣的是,在调试过程中,实例在保存后具有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);
        }
    }
}
使用系统;
使用NHibernate.Cfg;
使用SharpArch.Data.NHibernate;
使用LaboratorniMetody.Data.NHibernateMaps;
使用SharpArch.Core.PersistenceSupport;
使用实验室模拟体。核心;
命名空间LaboratorniMetody.FillSchema
{
班级计划
{
私有静态配置;
静态void Main(字符串[]参数)
{
configuration=NHibernateSession.Init(新SimpleSessionStorage(),新字符串[]{“LaboratorniMetody.Data”},
新建AutoPersistenceModelGenerator().Generate(),
“../../../../app/LaboratorniMetody.Web/NHibernate.config”);
IRepository LaboratoryRepository=新存储库();
实验室实验室1=新实验室(){Name=“Hematologie”};//方法
实验室l=LaboratoryRepository.SaveOrUpdate(Laboratory1);
Laboratory2=newLaboratory(){Name=“Patologie”};//方法
LaboratoryRepository.SaveOrUpdate(Laboratory2);
实验室实验室3=新实验室(){Name=“Laboratoře”};//方法
LaboratoryRepository.SaveOrUpdate(Laboratory3);
}
}
}
我使用NUnit从Project.Core类生成的DB模式


你知道我应该在哪里找到问题吗?我有2个非常类似的项目,没有问题的工作。我从其中一个复制了这段代码,实际上没有什么不同(除了DB模型等)。

您需要在事务中进行更改,然后提交事务

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();
}
使用(var tx=NHibernateSession.Current.BeginTransaction())
{
IRepository LaboratoryRepository=新存储库();
实验室实验室1=新实验室(){Name=“Hematologie”};//方法
实验室l=LaboratoryRepository.SaveOrUpdate(Laboratory1);
Laboratory2=newLaboratory(){Name=“Patologie”};//方法
LaboratoryRepository.SaveOrUpdate(Laboratory2);
实验室实验室3=新实验室(){Name=“Laboratoře”};//方法
LaboratoryRepository.SaveOrUpdate(Laboratory3);
tx.Commit();
}
我建议看一下SharpArchContrib项目wiki,其中有一些关于在windows应用程序/服务中使用SharpArch以及如何使用事务属性的示例


太好了,我相信它能奏效。但我仍然在思考为什么我的旧代码在旧项目中工作而在新项目中不工作。新旧代码之间有什么区别?如果答案有助于解决您的问题,请向上投票。