Nhibernate Cascade.All()不删除Cascade,为什么?
我需要删除在SlotTransceiver和端口上映射的端点成员。在过去,端点并没有自己的表,这个cklass是SlotTransceiver和Port的一部分 问题是,因为创建连接时rhitch引用了端点,所以我必须为端点创建自己的表。有更多的问题,但现在一切正常,除了级联删除端点行 我认为我需要为端点和连接编写重写类,或者为端口或SlotTransceiver更改此类 你能给我一些指示吗?我不是原始类的作者,我是Hibernate中的noob 我认为Cascade.All()意味着当我删除任何SlotTransceiver或端口时,它会自动删除引用的端点 是否存在来自新表连接的可能引用的问题 有以下几类:Nhibernate Cascade.All()不删除Cascade,为什么?,nhibernate,fluent-nhibernate,nhibernate-mapping,Nhibernate,Fluent Nhibernate,Nhibernate Mapping,我需要删除在SlotTransceiver和端口上映射的端点成员。在过去,端点并没有自己的表,这个cklass是SlotTransceiver和Port的一部分 问题是,因为创建连接时rhitch引用了端点,所以我必须为端点创建自己的表。有更多的问题,但现在一切正常,除了级联删除端点行 我认为我需要为端点和连接编写重写类,或者为端口或SlotTransceiver更改此类 你能给我一些指示吗?我不是原始类的作者,我是Hibernate中的noob 我认为Cascade.All()意味着当我删除任
public class EndPoint : Entity
{
private int _Position;
private VLAN _VLAN;
private string _Description;
private Connection _Connection;
[Min(0)]
public virtual int Position
{
get
{
return _Position;
}
set
{
_Position = value;
}
}
[NotNull]
public virtual VLAN VLAN
{
get
{
return _VLAN;
}
set
{
_VLAN = value;
}
}
[Length(500)]
public virtual string Description
{
get
{
return _Description;
}
set
{
_Description = value;
}
}
}
public class SlotTransceiver : Entity
{
private EndPoint _EndPoint;
private SlotTransceiverItem _InType;
private Slot _Slot;
[NotNull]
public virtual EndPoint EndPoint
{
get
{
return _EndPoint;
}
set
{
_EndPoint = value;
}
}
[NotNull]
public virtual SlotTransceiverItem InType
{
get
{
return _InType;
}
set
{
_InType = value;
}
}
[NotNull]
public virtual Slot Slot
{
get
{
return _Slot;
}
}
}
public class Port : Item
{ // Item is inherited from Entity
private EndPoint _EndPoint;
[NotNull]
public virtual EndPoint EndPoint
{
get
{
return _EndPoint;
}
set
{
_EndPoint = value;
}
}
}
public class Connection : Entity
{
private EndPoint _EndPointIn;
private EndPoint _EndPointOut;
[NotNull]
public virtual EndPoint EndPointIn
{
get
{
return _EndPointIn;
}
set
{
_EndPointIn = value;
}
}
[NotNull]
public virtual EndPoint EndPointOut
{
get
{
return _EndPointOut;
}
set
{
_EndPointOut = value;
}
}
}
它们是一些特殊映射:
public class SlotTransceiverOverride : IAutoMappingOverride<SlotTransceiver>
{
public void Override(FluentNHibernate.Automapping.AutoMapping<SlotTransceiver> mapping)
{
// in past EndPoint columns are in SlotTrancievers resp. in Ports tables
/*
mapping.Component(x => x.EndPoint, m =>
{
m.Map(x => x.Position);
m.Map(x => x.Description);
m.References(x => x.VLAN).ForeignKey("SlotTransceiversEndPointVLANFkConstraint");
});*/
mapping.References(x => x.InType).Not.LazyLoad();
mapping.References(x => x.EndPoint).Not.LazyLoad().Cascade.All();
}
}
public void Override(FluentNHibernate.Automapping.AutoMapping<Port> mapping)
{
// in past EndPoint columns are in SlotTrancievers resp. in Ports tables
/*
mapping.Component(x => x.EndPoint, m =>
{
m.Map(x => x.Position);
m.Map(x => x.Description);
m.References(x => x.VLAN).ForeignKey("PortsEndPointVLANFkConstraint");
});
*/
mapping.IgnoreProperty(x => x.AbsoluteIndex);
mapping.References(x => x.EndPoint).Not.LazyLoad();
mapping.References(x => x.EndPoint).Cascade.All();
}
公共类SlotTransceiverOverride:IAAutoMappingOverride
{
公共无效覆盖(FluentNHibernate.Automapping.Automapping映射)
{
//在过去,端点列分别位于插槽和端口表中
/*
组件(x=>x.EndPoint,m=>
{
m、 地图(x=>x.Position);
m、 映射(x=>x.Description);
m、 引用(x=>x.VLAN).ForeignKey(“slotTransceiverEndpointvlanFkConstraint”);
});*/
mapping.References(x=>x.InType).Not.LazyLoad();
mapping.References(x=>x.EndPoint).Not.LazyLoad().Cascade.All();
}
}
公共无效覆盖(FluentNHibernate.Automapping.Automapping映射)
{
//在过去,端点列分别位于插槽和端口表中
/*
组件(x=>x.EndPoint,m=>
{
m、 地图(x=>x.Position);
m、 映射(x=>x.Description);
m、 引用(x=>x.VLAN).ForeignKey(“PortsEndPointVLANFkConstraint”);
});
*/
mapping.IgnoreProperty(x=>x.AbsoluteIndex);
mapping.References(x=>x.EndPoint).Not.LazyLoad();
mapping.References(x=>x.EndPoint).Cascade.All();
}
结合NH属性和一些FNH自动映射的东西看起来非常可怕。我一点也不懂,但IMO经典类映射要透明得多。你必须用更多的击键来支付,但你的头痛会少一些:)
公共类端点映射:类映射
{
公共端点映射()
{
Id(x=>x.Id);
地图(x=>x.Position);
映射(x=>x.Description);
}
}
公共类连接映射:类映射
{
公共连接映射()
{
Id(x=>x.Id);
引用(x=>x.EndPointIn)
.Cascade.All()
.Not.LazyLoad();
引用(x=>x.EndPointOut)
.Cascade.All()
.Not.LazyLoad();
}
}
此代码还从数据库中删除连接和端点:
using (var session = OpenSession())
{
var connection = session.Get<Connection>(connectionId);
session.Delete(connection);
session.Flush();
}
使用(var session=OpenSession())
{
var connection=session.Get(connectionId);
删除(连接);
session.Flush();
}
结合NH属性和一些FNH自动映射的东西看起来非常可怕。我一点也不懂,但IMO经典类映射要透明得多。你必须用更多的击键来支付,但你的头痛会少一些:)
公共类端点映射:类映射
{
公共端点映射()
{
Id(x=>x.Id);
地图(x=>x.Position);
映射(x=>x.Description);
}
}
公共类连接映射:类映射
{
公共连接映射()
{
Id(x=>x.Id);
引用(x=>x.EndPointIn)
.Cascade.All()
.Not.LazyLoad();
引用(x=>x.EndPointOut)
.Cascade.All()
.Not.LazyLoad();
}
}
此代码还从数据库中删除连接和端点:
using (var session = OpenSession())
{
var connection = session.Get<Connection>(connectionId);
session.Delete(connection);
session.Flush();
}
使用(var session=OpenSession())
{
var connection=session.Get(connectionId);
删除(连接);
session.Flush();
}
谢谢您的回答。我认为不仅是FNH映射,而且所有NH看起来都非常可怕。我也不完全明白,但似乎它做了该做的事情。有时候…谢谢你的回答。我认为不仅是FNH映射,而且所有NH看起来都非常可怕。我也不完全明白,但似乎它做了该做的事情。有时