I use the following method to update entity in DbLinq.

Andrus.

        /// <summary>
        /// Saves entity to database updating only changed rows
        /// </summary>
        /// <param name="entityInEdit">new values</param>
        /// <param name="old">old values</param>
        /// <returns></returns>
        bool SaveOldEntity(TEntity entityInEdit, TEntity old)
        {
            using (Database db = new Database())
            {
                Table<TEntity> tbl = db.GetTable<TEntity>();
                TEntity trySave = new TEntity();
                trySave.CopyFrom(old);
                tbl.Attach(trySave);
                trySave.CopyFrom(entityInEdit);
                try
                {
                    db.SubmitChanges();
                }
                catch {
                    return false;
                }
            }
            old.CopyFrom(entityInEdit);
            return true;
        }

class EntityBase {

        public void CopyFrom(EntityBase fromObj)
        {
            foreach (PropertyInfo propertyInfo in GetType().GetProperties())
            {
                if (!propertyInfo.CanWrite)
                    continue;
                object oldv = propertyInfo.GetValue(fromObj, null);
                propertyInfo.SetValue(this, oldv, null);
            }
        }

}

----- Original Message ----- 
From: <[email protected]>
To: "DbLinq" <[email protected]>
Sent: Tuesday, April 21, 2009 6:30 PM
Subject: Re: Howto force update of entity





On Apr 21, 4:04 pm, Pascal Craponne <[email protected]> wrote:
> Have a look at the Attach() method and friends.
>

Attach isn't working for me.

I see the required method is ToDo. I'll have to see if I can use the
update code from elsewhere in that class in this method.

        [DbLinqToDo]
        public void ExecuteDynamicUpdate(object entity)
        {
            throw new NotImplementedException();
        }

Regards,

Greyman.




--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"DbLinq" 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/dblinq?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to