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 <[email protected]> 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.
>
> On Wed, Jul 29, 2009 at 4:57 AM, Nigel <[email protected]> wrote:
>
> > 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
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Fluent NHibernate" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/fluent-nhibernate?hl=en
-~----------~----~----~----~------~----~------~--~---