在提交后找不到实体

时间:2017-08-01 13:39:20

标签: c# postgresql nhibernate c#-5.0

保存实体并提交事务后,新实体出现在数据库中,但我无法找到他的GetById(),但如果我尝试一段时间后 - 我会找到它。

映射类:

public class NeformaliPamoka : EntityId
{
    public virtual long MoksloMetuMenesiaiId { get; set; }
    public virtual DateTime Data { get; set; }
    public virtual DateTime? LaikasNuo { get; set; }
    public virtual DateTime? LaikasIki { get; set; }
    public virtual long NeformaliosGrupesId { get; set; }
    public virtual DateTime IvedimoData { get; set; }
    public virtual long DarbuotojaiId { get; set; }
    public virtual string Turinys { get; set; }
}

XML映射:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
  <typedef class="Dal.CustomTypes.TamoTime, Dal" name="TamoTime"/>
  <class name="Model.NeformaliPamoka, Model" table="neformalios_pamokos">
    <id name="Id" type="Int64" unsaved-value="0">
      <column name="id" length="8" sql-type="bigint" not-null="true" unique="true" index="pk_neformalios_pamokos"/>
        <generator class="sequence">
            <param name="sequence">neformalios_pamokos_id_seq</param>
        </generator>
    </id>
    <property name = "MoksloMetuMenesiaiId" type="Int64">
      <column name="mokslo_metu_menesiai_id" length="8" sql-type="bigint" not-null="true"/>
    </property>
    <property name = "Data" type="DateTime">
      <column name="data" length="3" sql-type="timestamp" not-null="true"/>
    </property>
    <property name = "LaikasNuo" type="TamoTime">
      <column name="laikas_nuo" length="7" sql-type="time" not-null="false"/>
    </property>
    <property name = "LaikasIki" type="TamoTime">
      <column name="laikas_iki" length="7" sql-type="time" not-null="false"/>
    </property>
    <property name = "NeformaliosGrupesId" type="Int64">
      <column name="neformalios_grupes_id" length="8" sql-type="bigint" not-null="true"/>
    </property>
    <property name = "IvedimoData" type="DateTime">
      <column name="ivedimo_data" length="8" sql-type="timestamp" not-null="true"/>
    </property>
    <property name = "DarbuotojaiId" type="Int64">
      <column name="darbuotojai_id" length="8" sql-type="bigint" not-null="true"/>
    </property>
    <property name="Turinys" type="String">
      <column name="turinys"  sql-type="varchar" not-null="false" />
    </property>
  </class>
</hibernate-mapping>

我正在保存新实体并重定向到另一个操作。

这是保存方法:

public NeformaliPamoka SukurtiNeformaliaPamoka(long grupesId, DateTime data, DateTime laikasNuo, DateTime laikasIki)
{
    using (var transaction = DalFactory.GetTransaction())
    {
        try
        {

            var menesis = this.moksloMetuMenesiaiDal.GetMoksloMetuMenuoByDate(this.securityBll.CurrentIstaiguMoksloMetaiId.Value, data);

            var neformaliPamoka = new NeformaliPamoka();
            neformaliPamoka.DarbuotojaiId = securityBll.SelectedRolesIrasoId.Value;
            neformaliPamoka.Data = data;
            neformaliPamoka.IvedimoData = DateTime.Now;
            neformaliPamoka.MoksloMetuMenesiaiId = menesis.Id;
            neformaliPamoka.NeformaliosGrupesId = grupesId;
            neformaliPamoka.LaikasIki = laikasIki;
            neformaliPamoka.LaikasNuo = laikasNuo;
            neformaliPamoka.Turinys = "";

            this.neformaliPamokaDal.Save(neformaliPamoka);

            transaction.Commit();
            return neformaliPamoka;
        }
        catch
        {
            transaction.Rollback();
            throw;
        }
    }
}

这是在重定向上调用的Action:

    public ActionResult RedaguotiPamoka(long id)
    {
        BllFactory.SecurityCheckBll.CheckGaliPerzuiretiNeformaliaPamoka(id);
// other code
        return View("", Layout, model);
    }

在这种方法中我找不到实体。

public void CheckGaliPerzuiretiNeformaliaPamoka(long neformaliosPamokosId)
{

    var neformaliPamoka = this.neformaliPamokaDal.GetById(neformaliosPamokosId); // problem is here
    if (neformaliPamoka == null)
        throw new BllException("missed.", "INEXISTING_ENTITY");
}

如果我在这里设置BreakPoint,之后我会按f10 - 找到实体,如果我运行没有断点的代码 - 找不到实体。什么可能导致这个问题?我只在1层有这个问题。好像其他层工作正常。

var neformaliPamoka = this.neformaliPamokaDal.GetById(neformaliosPamokosId);

0 个答案:

没有答案