Reputation: 17085
For some time I couldn't find out the cause of an error when trying to update a field in a table using WCF Data Services plus Entity Framework:
MydbEntities context = new MydbEntities(new Uri("http://localhost:53051/Services/MydbService.svc"));
MyEntity entitytoedit = context.MyEntity.FirstOrDefault();
entitytoedit.Name = "TheNewName";
context.UpdateObject(entitytoedit);
context.BeginSaveChanges(OnChangesSaved, context);
...
The error was like following: RequestException An error occurred while processing this request.
The fix was to add an autoincremental decimal(18, 0)
field as the Primary Key with Identity Specification IsIdentity = yes
instead of just a varchar(20)
field as the Primary Key.
Please, could anybody explain the nature of the problem: should I always use autoincremental Primary Keys with WCF Data Services? If not, where in fact am I wrong?
Upvotes: 1
Views: 725
Reputation: 17589
I think it is more Entity Framework question than WCF Data Services.
You can either have primary key field that you set by hands and you must set StoreGeneratedPattern
to None
.
Or you can use AutoIncrement
field as primary key and in this case you must set StoreGeneratedPattern
for it to Identity
.
Mixing this to cases always break the things. In addition when you do Model First, primary key field by default has type int
and StoreGeneratedPattern
set to Identity
, so just changing the type to decimal
as in your case is not enough.
Upvotes: 1