TransactionException CheckNotZombied:トランザクションが接続されていない、または切断された] NHibernate.Transaction.AdoTransaction.CheckNotZombied()108
以下の方法で照会するNHibernateはを使用しながら、一方で
NHibernate.Transaction.AdoTransaction.Rollback()144複合キーと流暢NHibernateは列挙マッピング -
は、私は上記のエラーを取得しています:
以下public IEnumerable<Service> GetAllServicesByOrgType(OrganisationType orgType)
{
return NHibernateSession
.CreateCriteria<ServiceOrganisationType>()
.Add(Restrictions.Eq("OrganisationType", orgType))
.List<ServiceOrganisationType>()
.Select(x=>x.Service);
}
は私のデータベースです構造とFluentNHibernateマッピングとモデル:
データベース構造
Service:
- Id(PK)
- Name (nvarchar)
ServiceOrganisationType (composite PK on OrganisationTypeId and ServiceId):
- OrganisationTypeId (PK)
- ServiceId (PK)
- LastUpdated
- LastUpdatedById
OrganisationType:
- Id (PK)
- OrganisationType (nvarchar)
ServiceOrganisationTypeMap:
public class ServiceOrganisationTypeMap : ClassMap<ServiceOrganisationType>
{
public ServiceOrganisationTypeMap()
{
CompositeId()
.KeyReference(x => x.Service, "ServiceId")
.KeyProperty(x => x.OrganisationType, "OrganisationTypeId");
References(x => x.LastUpdatedBy);
Map(x => x.LastUpdated);
}
}
ServiceMap:
public class ServiceMap : ClassMap<Service>
{
/// <summary>
/// Initializes a new instance of the ServiceMap class.
/// </summary>
public ServiceMap()
{
Id(x => x.Id).GeneratedBy.Identity();
Map(x => x.Name);
HasMany(x => x.ServiceOrganisationTypes)
.KeyColumn("ServiceId")
.Inverse()
.Cascade
.AllDeleteOrphan();
// Other mappings...
}
}
OrganisationTypeは列挙型です:
public enum OrganisationType : long
{
FirstOrgTypeExample = 1,
SecondOrgTypeExample = 10,
ThirdOrgTypeExample = 30
}
サービスモデルクラス:
[Serializable]
public class Service : DomainObject
{
// Other model properties...
public virtual IList<ServiceOrganisationType> ServiceOrganisationTypes { get; set; }
}
ServiceOrganisationTypeモデルクラス:列挙型の場合
[Serializable]
public class ServiceOrganisationType : AuditedObject
{
[NotNull]
public virtual OrganisationType OrganisationType { get; set; }
[NotNull]
public virtual Service Service { get; set; }
public override bool Equals(object obj)
{
if (obj == null)
return false;
var t = obj as ServiceOrganisationType;
if (t == null)
return false;
if (OrganisationType == t.OrganisationType && Service == t.Service)
return true;
return false;
}
public override int GetHashCode()
{
return (OrganisationType + "|" + Service.Id).GetHashCode();
}
}
、私はまた、このポストの答えの中に記述さEnumConventionクラスを使用しています:Enum to integer mapping causing updates on every flush。だから、私のAcceptメソッドは以下のようになります:
public void Accept(IAcceptanceCriteria<IPropertyInspector> criteria)
{
criteria.Expect(
// ... Other arguments ||
// We want all instance of OrganisationType to map to long
x.Property.PropertyType == typeof(OrganisationType)
);
}
私はCheckNotZombiedが他の何かの症状であると推測しています。 「System.Data.SqlClient.SqlException:エラーBIGINTするデータ型はnvarcharを変換」 - - 私はNHProfをチェックするときには、SQLエラーを示し、ServiceOrganisationTypeテーブルを照会しながらNHibは、以下のSQLを生成する:で
SELECT this_.ServiceId as ServiceId63_0_,
this_.OrganisationTypeId as Organisa2_63_0_,
this_.LastUpdated as LastUpda3_63_0_,
this_.LastUpdatedById as LastUpda4_63_0_
FROM MyDb.dbo.[ServiceOrganisationType] this_
WHERE this_.OrganisationTypeId = 'FirstOrgTypeExample' /* @p0 */
をWHERE節では、の長さがの値ではなく、列挙型( 'FirstOrgTypeExample')の文字列値を使用しています。私は、基準クエリの実行中にlongにOrganisationTypeをキャストしようとしたが、その後のマッピング例外が言ってスローされます。
NHibernate.QueryException: NHibernate.Criterion.SimpleExpressionで型の不一致:OrganisationType期待タイプ MYPRODUCT。 MyProject.Core.OrganisationType、実際の型System.Int64
NHibernateに生成されたSQLでenum値を使用させる方法は誰でも手助けできますか?
おかげ
OrganisationTypeId列はnullableではないので、これは当てはまりません – Robbie