简体   繁体   English

使用ria-services更新来自单个实体的单个字段

[英]Update a single field from a single entity with ria-services

There are situations where I only want to update a specific field of a single entity in the database. 在某些情况下,我只想更新数据库中单个实体的特定字段。

I loaded the entities of that type into my silverlight application, and I know they are constantly changing on the server... but there is one field which has to be set by the silverlight client... the server will only read it. 我将这种类型的实体加载到了Silverlight应用程序中,并且我知道它们在服务器上一直在变化……但是Silverlight客户端必须设置一个字段……服务器只会读取它。 How can I just send the new data for that field to the server? 我如何才能将该字段的新数据发送到服务器?

Example an Entity called "TextField". 例如,一个名为“ TextField”的实体。 I have a list of TextFields loaded in the silverlight application and every now and then the user will update the Preload (string) property of an entity and that has to go back to the server without changing anything else on the server. 我在Silverlight应用程序中加载了一个TextField列表,用户不时会更新实体的Preload(字符串)属性,该属性必须返回到服务器,而无需更改服务器上的任何其他内容。

I tried adding a simple SetPreloadText(...) method to the DomainService but that just makes Silverlight crash with some odd error code. 我尝试将简单的SetPreloadText(...)方法添加到DomainService,但这只会使Silverlight崩溃,并带有一些奇怪的错误代码。

Is there a way to this? 有办法吗? Am I working against the idea of Silverlight here? 我在这里反对Silverlight的想法吗? I really don't want to send the entire object back because know that at any given time the version on the client will most likely be out of date. 我真的不希望将整个对象发回,因为知道在任何给定时间,客户端上的版本很可能已经过时。 (which is ok for this specific application) (对于此特定应用程序可以)

I think SetPreloadText(..) chrashes because RIA Services uses special naming coneventions like insert/update/delete for crud unless you specify it to be named different. 我认为SetPreloadText(..)会崩溃,因为RIA Services使用特殊的命名约定,例如为crud使用insert / update / delete,除非您将其指定为不同的名称。

If you only want to update a specific property because the other my not have changed. 如果您只想更新特定属性,因为其他我没有改变。 You should look at 你应该看看

this.Context.AttachAsModified(currentEntityWithAllTextFields, this.ChangeSet.GetOriginal(currentEntityWithAllTextFields));

in your update method. 在您的更新方法中。 With this you can exactly filter out what changed... 有了这个,您可以准确地过滤出发生了什么变化...

hope this helps... 希望这可以帮助...

Now you need to use this : 现在您需要使用:

  this._yourENtitySet.Value.ApplyCurrentValues(modified); // The one you received
  this._yourENtitySet.Value.ApplyOriginalValues(original); /// The original one

Hope this help ! 希望对您有所帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM