changes on OnBeforeEntitySave

Posts   
 
    
Pipo
User
Posts: 8
Joined: 07-May-2007
# Posted on: 04-Jun-2007 19:48:56   

Hello,

workring on .NET 2.0 and llblgen 2.0 (adapter) i've got a problem saving a entity. I've overwritten the event OnBeforeEntitySave of my entity "TblFirmenEntity". In my function i want to add a child entity "TblAbtZEntity" to TblFirmenEntity. Every things works. the count of the entitycollection "TblAbtZ" is increased. My problem is that the dataaccessadapter doesn't save it. I think he don't know the added entity. When i add it manually from the winform before calling the adapter.saveentity(TblFirmenEntity) it works. Is there any Method to tell the dataadapter that the child entity collection has changed or new members?


    public partial class TblFirmenEntity
    {
        protected override void OnBeforeEntitySave()
        {
            base.OnBeforeEntitySave();
            setFieldValuesBeforeSave();
        }

        private void setFieldValuesBeforeSave()
        {
            if (this.IsNew)
            {
                this.XxxAnAm = DateTime.Now;
                this.XxxAnVon = HIS.Helper.UserLoggedOn.UserName;
                this.XxxAnWs = HIS.Helper.UserLoggedOn.Workstation;
            }
            else
            {
                this.XxxGeAm = DateTime.Now;
                this.XxxGeVon = HIS.Helper.UserLoggedOn.UserName;
                this.XxxGeWs = HIS.Helper.UserLoggedOn.Workstation;
            }

// here i wan't to add the users department to the current TblFirmenEntity.
            JoinAbtZ();
        }

        private void JoinAbtZ()
        {
            if (this.TblAbtZ != null)
            {
                EntityCollection<TblAbtZEntity> abtz = this.TblAbtZ;

                List<int> nfound = abtz.FindMatches(new PredicateExpression(TblAbtZFields.AbzAbtId == HIS.Helper.UserLoggedOn.DepartmentId));
                if (nfound.Count == 0)
                {
                    TblAbtZEntity newitem = new TblAbtZEntity();
                    newitem.AbzAbtId = HIS.Helper.UserLoggedOn.DepartmentId; // SESSION
                    TblAbtZ.Items.Add(newitem);
                }
            }
        }

    
    }

jmeckley
User
Posts: 403
Joined: 05-Jul-2006
# Posted on: 04-Jun-2007 21:51:18   

try this instead

public partial class TblFirmenEntity
    {
        protected override void OnBeforeEntitySave()
        {
            setFieldValuesBeforeSave();
            base.OnBeforeEntitySave();
        }

Pipo
User
Posts: 8
Joined: 07-May-2007
# Posted on: 05-Jun-2007 10:08:19   

same result. Doesn't work.

Pipo
User
Posts: 8
Joined: 07-May-2007
# Posted on: 05-Jun-2007 10:27:07   

chnages on the existing tblAbtEntity objects are working.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 05-Jun-2007 10:29:14   

I think you are miss using the OnBeforeEntitySave, it's only ment for last minute changes to the entity fields, not to add related entities, as described in the following thread: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=8412

Pipo
User
Posts: 8
Joined: 07-May-2007
# Posted on: 05-Jun-2007 10:55:37   

Hy walaa, thanks. but it doesn't solve my problem. is there another event that can be used before saving to add entities?

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 05-Jun-2007 10:58:47   

In the thread link I've posted, Frans explains how you can add those changes.

Pipo
User
Posts: 8
Joined: 07-May-2007
# Posted on: 05-Jun-2007 11:45:23   

sorry,

thank you