Print Page | Close Window

Saving a single row

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=2131
Printed Date: 10-Jun-2026 at 5:33pm


Topic: Saving a single row
Posted By: xkubr
Subject: Saving a single row
Date Posted: 06-Sep-2010 at 1:06am
I have just started working with DevForce 2010 so this question may be obvious to those with experience using this product. My question is simply: How do I save a single row in the database? I have a table (Ticket) that has been modeled along with all related tables. In my app the user has selected a row in a grid and made changes to the values. The user may have changed values for several rows in the grid but only needs to save one of the rows, not the entire "dataset".

I have implemented the Manager.SaveChanges, passing in an IEnumerable of Tickets but this saves all the row changes. The app is WPF, Windows, .Net 4.0, MVVM using a standard datagrid.

Can someone give me a pointer in the right direction?

Thanks.



Replies:
Posted By: smi-mark
Date Posted: 06-Sep-2010 at 5:47pm
If you only add the entity you are working with to the list, and then pass that to SaveChanges, it will only save one, not everything.


Posted By: xkubr
Date Posted: 07-Sep-2010 at 2:22am
Thank you for your post\reply.

We had considered this strategy already and it does not fit well with our requirements. Saving a single object\row from the collection using this method requires a separate list to be created. What we are looking for is a Save method exposed that accepts either a single object or the existing list and the index of the object to save. In the scenario I describe above this would allow for one row to be saved (updated) and any other rows (that may also have changes pending) are left unsaved. This is (unfortunately) a fairly strict business requirement.

Any thought or comments pls feel free to post them.


Posted By: smi-mark
Date Posted: 07-Sep-2010 at 2:40pm
Can you not write a method such as this?

public static class EntityManagerExtensions
{
            public static SaveResult SaveSingle(this DomainModelEntityManager manager, object row)
             {
                 return manager.SaveChanges(new object() {row});
              }
}

or even

public static class EntityExtensions
{
            public static SaveResult SaveChanges(this IdeaBlade.EntityModel.Entity entity, object row)
             {
                 return entity.EntityAspect.EntityManager.SaveChanges(new object() {row});
              }
}

Now you call row.SaveChanges() or manager.SaveSingle(row)


Posted By: xkubr
Date Posted: 08-Sep-2010 at 6:15am
Yip, that worked. It just never occurred to me to have to create and pass in a list with a single item in order to save just 1 row.

Thank you.


Posted By: ting
Date Posted: 08-Sep-2010 at 6:26pm
Thanks for the help Mark.  You've always been great!



Print Page | Close Window