| Author |
Share Topic Topic Search Topic Options
|
xkubr
Newbie
Joined: 01-Sep-2010
Posts: 6
|
Post Options
Quote Reply
Topic: Saving a single row 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.
|
 |
smi-mark
DevForce MVP
Joined: 24-Feb-2009
Location: Dallas, Texas
Posts: 343
|
Post Options
Quote Reply
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.
|
 |
xkubr
Newbie
Joined: 01-Sep-2010
Posts: 6
|
Post Options
Quote Reply
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.
|
 |
smi-mark
DevForce MVP
Joined: 24-Feb-2009
Location: Dallas, Texas
Posts: 343
|
Post Options
Quote Reply
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)
|
 |
xkubr
Newbie
Joined: 01-Sep-2010
Posts: 6
|
Post Options
Quote Reply
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.
|
 |
ting
IdeaBlade
Joined: 27-Mar-2009
Location: San Francisco
Posts: 427
|
Post Options
Quote Reply
Posted: 08-Sep-2010 at 6:26pm |
Thanks for the help Mark. You've always been great!
|
 |