I have a problem here and no have ideia to solution this.
I have 2 classes:
public class Previa
{
public virtual int Id { get; set; }
public virtual DateTime Date { get; set; }
public virtual string Description { get; set; }
public virtual IList<ItemPrevia> ListItemPrevia{ get; set; }
}
public class ItemPrevia
{
public virtual int Id { get; set; }
public virtual string Description { get; set; }
public virtual decimal Price { get; set; }
public virtual Previa Previa { get; set; }
}
and Mapping:
public class PreviaMap : ClassMap<Previa>
{
public PreviaMap()
{
Id(f => f.Id)
.Length(11);
Map(f => f.Date)
.Not.Nullable();
Map(f => f.Description)
.Not.Nullable();
HasMany<ItemPrevia>(m => m.ListItemPrevia)
.Table("ItemPrevia")
.Inverse()
.Cascade.AllDeleteOrphan()
.Not.LazyLoad();
}
}
public class ItensPreviaMap : ClassMap<ItemPrevia>
{
public ItensPreviaMap()
{
Id(f => f.Id)
.Length(11);
Map(f => f.Description)
.Not.Nullable();
Map(f => f.Price)
.Not.Nullable();
References(f => f.Previa).Column("IdPrevia").Not.LazyLoad();
}
}
In my system i have to register a Previa and after, include some ItemPrevia.
But, i can inform the another Previa and copy your items to the current Previa.
How I could persist the list of the other Previa for the current Previa ?
I Try this:
Previa objPreviaOld = new Previa();
objPreviaOld = PreviaBLL.Search(Convert.ToInt32(txtPreviaOld.Text));
if (objPreviaOld != null)
{
foreach (ItemPrevia objItemPrevia in objPreviaOld.ListItemPrevia)
{
objItemPrevia.Id = 0;
objItemPrevia.Previa = objPrevia;
objPrevia.ListItemPrevia.Add(objItemPrevia);
}
PreviaBLL.Alter(objPrevia);
}
But occur this error: identifier of an instance of Domain.Entities.ItemPrevia was altered from 50 to 0
Someone help me ?
as @Merlyn Morgan-Graham said you have to copy the data to new objects.