Don't change the reference to a collection with cascade="all-delete-orphan"

908 views
Skip to first unread message

Nigel

unread,
Jul 28, 2009, 2:57:32 PM7/28/09
to Fluent NHibernate
I have an entity with children. I need to loop through the children
and update a date time field. When I try to save the parent (item) or
the child (doc) I get the Don't change the reference to a collection
with cascade="all-delete-orphan" error. Funny thing is I don't think I
am changing the reference to the collection, just setting a date
field.

I get this error whether I save with the parent _opsItemRepository or
the _OpsItemRepository.

var item = _OpsItemRepository.Get(OpsItemId);
if (item != null)
{
foreach (var doc in item.OpsDocs)
{
var fullFileName = Path.Combine
(TIFDestinationPath, doc.OpsDocId + ".TIF");
if (!doc.Exported.HasValue)
{
if (File.Exists(finalFileName))
{
doc.Exported = DateTime.Now;
_OpsDocRepository.SaveOrUpdate(doc);
}
}
}
}


Any ideas?

Thanks,
Nigel

Paul Batum

unread,
Jul 28, 2009, 10:22:00 PM7/28/09
to fluent-n...@googlegroups.com
I cannot see anything wrong with the code that you have shown. You need to give us more information on the error that is occuring, and your entity mappings.

Nigel

unread,
Jul 29, 2009, 9:52:16 AM7/29/09
to Fluent NHibernate
Here is the mapping.

public class OpsItem : NHibernateEntityBase<OpsItem>,
IHasCreatedModified
{
public override int Id
{
get { return OpsItemId; }
}

public virtual int OpsItemId { get; set; }
public virtual int DocSourceId { get; set; }
public virtual int ItemId { get; set; }
public virtual int LoadId { get; set; }
public virtual string Note { get; set; }
public virtual DateTime CreatedDate { get; set; }
public virtual string CreatedBy { get; set; }
public virtual DateTime ModifiedDate { get; set; }
public virtual string ModifiedBy { get; set; }
public virtual byte[] Timestamp { get; set; }
public virtual bool NoteProcessed { get; set; }

public virtual DocSource DocSource { get; set; }
public virtual IList<OpsDoc> OpsDocs { get; set; }

public string ItemNumber
{
get
{
return (DocSourceId == (int)DocumentTypes.Pro)
? ItemId + "." + LoadId
: ItemId.ToString();
}
}

public OpsItem()
{
OpsDocs = new List<OpsDoc>();
}

protected override void ValidateResults(ValidationResults
results)
{

}
}

public class OpsItemMap : TrnjClassMap<OpsItem>
{
public OpsItemMap()
{
WithTable("OpsItem");
Id(x => x.OpsItemId);
Map(x => x.DocSourceId).SetAttributes(new Attributes
{ { "insert", "false" }, { "update", "false" } }); ;
Map(x => x.ItemId);
Map(x => x.LoadId);
Map(x => x.Note);
Map(x => x.CreatedDate).TheColumnNameIs("DateCreated");
Map(x => x.CreatedBy);
Map(x => x.ModifiedDate).TheColumnNameIs("DateModified");
Map(x => x.ModifiedBy);
Version(x => x.Timestamp);
Map(x => x.NoteProcessed);
References(x => x.DocSource,
"DocSourceId").FetchType.Select();
HasMany<OpsDoc>(x => x.OpsDocs).WithKeyColumn
("OpsItemId").IsInverse().Cascade.AllDeleteOrphan();
}
}


On the previous post I meant to say I get the error from parent
_opsItemRepository or child _opsDocRepository.

On Jul 28, 10:22 pm, Paul Batum <paul.ba...@gmail.com> wrote:
> I cannot see anything wrong with the code that you have shown. You need to
> give us more information on the error that is occuring, and your entity
> mappings.
>

Paul Batum

unread,
Aug 3, 2009, 5:11:56 PM8/3/09
to fluent-n...@googlegroups.com
Hi Nigel,

Sorry for the delay, I lost track of this one. Have you made any progress on this one? If not, can you include the details of the actual error?

Paul Batum
Reply all
Reply to author
Forward
0 new messages