I have tried may different relation options but they all seem to fail.
Major issue seems to be the Child Refrence in the component
The rules
Only an existing item can be added as a child item.
The mater item can not have a ref to self
A child item can only be added on time.
What I want the application code to look like
Item childItem = new Item("200", "Item 200");
childItem.Save();
Item masterItem = new Item("100", "Item 100");
masterItem.Add(childItem, 10);
masterItem.Save();
classes
public abstract class Arbase<T>:ActiveRecordBase<T>
{
[PrimaryKey]
public virtual Int32 ID { get; set; }
[Version]
public virtual DateTime version { get; set; }
}
[ActiveRecord]
public class Item:Arbase<Item>
{
private IList<Component> _l = new List<Component>();
public Item() { }
public Item(string no,string dsc)
{
this.ItemNO = no;
this.Description = dsc;
}
[Property(Unique=true)]
public virtual string ItemNO { get; set; }
[Property]
public virtual string Description { get; set; }
[HasMany]
public virtual IList<Component> Components
{
get { return _l; }
set { _l = value; }
}
public Component Add(Item child,int qty)
{
Component c=new Component(this,child,qty);
this.Components.Add(c);
return c;
}
}
[ActiveRecord]
public class Component:Arbase<Component>
{
public Component() { }
public Component(Item master,Item child, int qty)
{
this.Master = master;
this.Child = child;
this.Qty = qty;
}
[BelongsTo("Master")]
public virtual Item Master { get; set; }
[Property]
public virtual Item Child { get; set; }
[Property]
public virtual Int32 Qty { get; set; }
}
--
You received this message because you are subscribed to the Google Groups
"Castle Project Users" 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/castle-project-users?hl=en.