With assigned IDs, AR cannot know whether the cascaded record exists.
It tries to update, but doesn't find any row for updating. It also
cannot assume a new row because the row count of 0 may also indicate a
stale object due to a version or timestamp field (concurrent change
with optimistic locking).

-Markus

2009/6/1 raghavsri <[email protected]>:
>
> I have created three classes parent ,child and grandchild and also I
> have established relationship among them using, BelongsTo and HasMany
> attributes provided by theActiverecord. I have set Primary key
> attribute as native.Cascade is set to All and inverse to false.
>
> When I execute parent.create().. it is saving parent,child and
> grandchild.
>
> But when I use Primary key attribute as assigned.. and execute
> parent.Create(). It is throwing an exception as “unexpected row count
> is 0: expected row is 1:”
>
> Please let me know , what is the procedure to use assigned
> attribute .
>
>
> namespace ActiveRecordcheckcascade
> {
> class Program
> {
> static void Main(string[] args)
> {
> ActiveRecordStarter.Initialize(typeof(Parent).Assembly,
> ActiveRecordSectionHandler.Instance);
> //execute this only once.. to crate tables.from next executtion
> //it is not required
> ActiveRecordStarter.CreateSchema();
> Parent oParent = new Parent();
> Children oChild = new Children();
> GrandChild oGrandChild = new GrandChild();
>
> oChild.CID = 123;
> oParent.PID = 124;
> oGrandChild.GCID = 123;
>
> IList<Children> oChildLists = new List<Children>();
> IList<GrandChild> oGrandChildList = new List<GrandChild>();
> oChildLists.Add(oChild);
> oGrandChildList.Add(oGrandChild);
>
> oParent.SetChildren(oChildLists);
> oChild.SetGrandChild(oGrandChildList);
>
> oParent.Create();
> }
> }
>
>
> [ActiveRecord]
> public class Parent:ActiveRecordBase<Parent>
> {
> private long pid;
> private IList< Children> oChildList;
>
> public Parent()
> {
> oChildList = new List<Children>();
> }
>
> [PrimaryKey(Generator = PrimaryKeyType.Assigned, Access =
> PropertyAccess.Property)]
> public long PID
> {get {return pid;}
> set { pid = value; }
> }
>
> [HasMany(Table = "Children", ColumnKey = "PID", Inverse = false,
> Cascade = ManyRelationCascadeEnum.All)]
> public IList<Children> Children { get { return oChildList; } set
> { oChildList = value; } }
>
> public void SetChildren(IList<Children> oChilds)
> {
> oChildList = oChilds;
> }
> }
>
> [ActiveRecord]
> public class Children:ActiveRecordBase<Children>
> {
> private int cid;//child id
> private IList<GrandChild> ograndChildList;
>
> public Children()
> {
> ograndChildList = new List<GrandChild>();
> }
>
> [PrimaryKey(Generator =
> PrimaryKeyType.Assigned,Access=PropertyAccess.Property)]
> public int CID
> { get { return cid; } set { cid = value; } }
>
> [HasMany(Table = "GrandChildre", ColumnKey = "CID", Inverse = false,
> Cascade = ManyRelationCascadeEnum.All)]
> public IList<GrandChild> GrandChildList { get { return
> ograndChildList; } set { ograndChildList = value; } }
>
> [BelongsTo("PID")]
> public Parent PID { get ; set; }
>
> public void SetGrandChild(IList<GrandChild> ograndChilds)
> {
> ograndChildList = ograndChilds;
> }
> }
>
> [ActiveRecord]
> public class GrandChild : ActiveRecordBase<GrandChild>
> {
> private int gcid;// grand child id
> [PrimaryKey(Generator =
> PrimaryKeyType.Assigned,Access=PropertyAccess.Property)]
> public int GCID
> { get { return gcid; } set { gcid = value; } }
>
> [BelongsTo("CID")]
> public Children grandchildparent { 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
-~----------~----~----~----~------~----~------~--~---

Reply via email to