English 中文(简体)
流利Nhibernate: 删除“Hasmany”财产中的一个项目
原标题:Fluent Nhibernate: Cant delete an item with as HasMany property

我通常会处理类似数据,但我认为,这样做是徒劳的。 既然我反对,我就失败了:而且不清楚如何继续工作。

我有一个数据库目标轨道:

public virtual string Type { get; set; }

public virtual IList<DateTypeTrack> TrackDates { get; set; }

有一个绘图档案:

Table("Tracks");
Map(x => x.Type).Not.Nullable();
HasMany(x => x.TrackDates).KeyColumn("TrackID").Cascade.All();

日惹 目标:

public virtual DateType DateType { get; set; }
public virtual Track Track { get; set; }
public virtual int Days { get; set; }

这里有类似地图:

Table("DateTypeTracks");
References(x => x.DateType, "DateTypeID").Not.Nullable();
References(x => x.Track, "TrackID").Not.Nullable();
Map(x => x.Days).Not.Nullable();

如果有必要,Ill将《日期Type法典》张贴在前面,但我想到了需要。

并且试图在我的服务层中写出一种非常简单的删除方法:

public void PushDelete(int id)
    {
        Track track = _tracks.Get(id);

        try
        {
            _tracks.BeginTransaction();
            _tracks.Delete(track);
            _tracks.CommitTransaction();
        }
        catch (Exception)
        {
            _tracks.RollbackTransaction();
            throw;
        }
    }

我犯了一个错误:

could not delete collection: [TSE.Domain.DatabaseObjects.Track.TrackDates#12][SQL: UPDATE DateTypeTracks SET TrackID = null WHERE TrackID = @p0]

我很想知道,为什么要最终完成更新工作,但我相信,这是造成这一问题的原因。 我有什么办法?

感谢。

最佳回答

自<代码>DateTypeTrack以来 请将Hasmany记为

HasMany(x => x.TrackDates).KeyColumn("TrackID").Cascade.All().Inverse();
问题回答

暂无回答




相关问题
Does Fluent NHibernate support "trigger-identity"

I posted the question in the Fluent-NHibernate newgroup but so far there has been no answer from the void. Is there a Fluent NHibernate mapping for the NHibernate "trigger-identity" method of ...

automapping nested components naming conventions

Im making the switch from Fluent Mapping to Automapping in my current project. If I have the following domain: public class Matter{ public Client Client{get;set;} } public class Client { ...

NHibernate Search in a List using ICriteria

I have my class X : public class ClassX { public virtual IList<ClassY> ListY { get; set; } ... } My ClassX mapping (using Fluent) ... HasMany<ClassX>(x => x.ListY ) ....

Fluent nHibernate keeps recreating my database, why?

I m trying to convert my data layer from Linq2Sql to nHibernate. I think Xml the configuration in nHibernate is pretty backwards so I m using Fluent. I ve managed to get fluent, add in a repository ...

How to fluent-map this (using fluent nhibernate)?

I have two tables in my database "Styles" and "BannedStyles". They have a reference via the ItemNo. Now styles can be banned per store. So if style x is banned at store Y then its very possible that ...