THESE FORUMS ARE NOW FROZEN
Please choose "Forums" from the Main menu of www.entityspaces.net to get to our new forums.

WCF Collection Save

rated by 0 users
This post has 2 Replies | 0 Followers

Top 500 Contributor
Posts 5
cajones Posted: 11-23-2009 6:40 AM

Hi,

This may be a pretty basic question, but...

I can't update existing records as I get an SQL 'duplicating PK value' error when attempting to save to the database.  Saving new records is not a problem  The PK value is set in the proxystub from the existing PK value the client received when originally loading the record. I'm using the code as per ES example:

 

 

 

public EmployeesCollectionProxyStub Collection_Save(EmployeesCollectionProxyStub

collection){

 

collection.GetCollection().Save();

 

Can you tell me what I'm doing wrong?  Does 'GetCollection().Save();' update existing records? Or do I need to load an EmployeesCollection by primary key, and then copy the EmployeesCollectionProxyStub  data into it and then save the EmployeesCollection?

Thanks in advance for your help.

Top 10 Contributor
Posts 3,881

Yes, it should just "save". In fact, our Silverlight demo does just this, it uses WCF and is installed with our product. As long as you have the Microsoft SQL Northwind database you can run it and see how it works. You just need to be sure and always load your primary keys of course and not just select say a "name" field and not also load the EmployeeID. You definitely don't want to reload the data.

Take a look at our silverlight sample.

EntitySpaces | Twitter | BLOG | Please honor our Software License

Top 500 Contributor
Posts 5

Hi Mike,

Thank you for your quick response.  Yes I have had a look at the example and have been using WCF with ES and SQL Server 2005 for some time and everything works fine. 

What I've found is that updating a record where the primary key is on a column which is an identity, indexable and an int type works OK. 

However the problem happens when we try and update a record (e.g. in Address Table, as shown bellow) whose primary key is a string which isn't set as an identity column .  Whose unique values are created as guids (generated externally by the client application).   Under this scenario (1) Works but (2) Doesn't

1) Works


WCFFunction_SaveAddress(AddressCollectionProxyStub collection)

Address add = new Address

add.LoadByPrimaryKey(collectionIdea.AddressID)

add.StuffField = collectionIdea.StuffField;
...

add.Save();


2) Doesn't Work


WCFFunction_SaveAddress(AddressCollectionProxyStub collection)

collection.GetCollection().Save();

Does this scenario somehow relate to your comment - "always load your primary keys of course and not just select say a "name" field"? (I'm not sure what this means)

Page 1 of 1 (3 items) | RSS
Copyright © 2005 - 2009, EntitySpaces, LLC