InvalidOperationException "The value of the member" X "of the object of type" Y "has been changed." when saving data through WCF and LINQ data services

I have a system that uses WCF data services on top of the .dbml data model (System.Data.Linq.DataContext). The client receives the data it needs, System.Data.Services.Client.DataServiceContextmakes changes and saves the data through WCF data services, which in turn saves the SQL Server database. The class DataContexthas an implementation IUpdateablevery similar to this example .

I find this a bit odd and it was built several years ago, so there are probably a lot better ways to do it now, but overall it all works well. However, he was recently deployed to a new environment and began to have problems in accordance with

An exception of type 'System.Data.Services.Client.DataServiceRequestException' occurred and was caught.
... 
Value of member 'BehaviorAsString' of an object of type 'profile' changed.
A member that is computed or generated by the database cannot be changed.

The problem column is BehaviorAsStringcalculated in the view that is the source for the object profile. In dbml, it is correctly set to ReadOnly = True, since it should never be updated. The stack trace shows that the problem is happening on the server side (as I interpret it - see below).

It is still so simple: the problem is that my user interface for some reason updates this property, then my DataService rightly complains that this is not allowed.

, . - .xaml, TextBlock ( readonly). WPF . , , , () . DataService , . LinqToSql , ReadOnly .

, - , , , .

, BehaviorAsString, . , ReadOnly . , .

, , , .

, , , , . , , , , . . (NB: . 3 - - DataContext). , ​​ .NET - .NET v2.0 , .NET 3.5 SP1, , . dll .

, :

  • , WCF, , LINQ ?

  • - , , ?

!


, :

Message: An exception of type 'System.Data.Services.Client.DataServiceRequestException' occurred and was caught.
02/13/2014 16:05:20
Type: System.Data.Services.Client.DataServiceRequestException, System.Data.Services.Client, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
Message: An error occurred while processing this request.
InnerException(s):
  System.Data.Services.Client.DataServiceClientException: <?xml version="1.0" encoding="utf-8" standalone="yes"?>
<error xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
  <code></code>
  <message xml:lang="en-US">An error occurred while processing this request.</message>
  <innererror>
    <message>Value of member 'BehaviorAsString' of an object of type 'profile' changed.&#xD;
A member that is computed or generated by the database cannot be changed.</message>
    <type>System.InvalidOperationException</type>
    <stacktrace>   at System.Data.Linq.ChangeProcessor.CheckForInvalidChanges(TrackedObject tracked)&#xD;
   at System.Data.Linq.ChangeProcessor.SubmitChanges(ConflictMode failureMode)&#xD;
   at System.Data.Linq.DataContext.SubmitChanges(ConflictMode failureMode)&#xD;
   at System.Data.Linq.DataContext.SubmitChanges()&#xD;
   at RPServices.RPDataModel.RPDataModelDataContext.SaveChanges()&#xD;
   at System.Data.Services.DataService`1.BatchDataService.HandleBatchContent(Stream responseStream)</stacktrace>
  </innererror>
</error>

   at System.Data.Services.Client.DataServiceContext.SaveResult.<HandleBatchResponse>d__1e.MoveNext()
Source: System.Data.Services.Client
TargetSite: Void HandleBatchResponse()
StackTrace:    at System.Data.Services.Client.DataServiceContext.SaveResult.HandleBatchResponse()
   at System.Data.Services.Client.DataServiceContext.SaveResult.EndRequest()
   at System.Data.Services.Client.DataServiceContext.SaveChanges(SaveChangesOptions options)
   at RPAdminTool.ViewModel.ViewModelBase.SaveProcess()
   at RPAdminTool.ViewModel.ViewModelBase.<Save>b__2(Object _, DoWorkEventArgs __)

1:

(?), , .

2:

IUpdateable ... IUpdatable.SaveChanges(), , IsDbGenerated=true?

3:

, : -/, , (WPF) DataServiceChannel ( RPDataModelDataContext) . , , , DataServiceQuery.Expand(), . , DataServiceChannel , / , .

, DataServiceChannel, , . , , . , , , .

+4
1

WCF Linq2Sql, ?

, , (DTO). , , , .

Code First, , , serialiser .

0

Source: https://habr.com/ru/post/1529908/


All Articles