Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/entity-framework/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wcf 仅更新已修改的列_Wcf_Entity Framework_Odata - Fatal编程技术网

Wcf 仅更新已修改的列

Wcf 仅更新已修改的列,wcf,entity-framework,odata,Wcf,Entity Framework,Odata,我有使用EF和Oracle Data Provider for.Net的OData服务(WCF Data Services 5.6)。 当我将查询从服务跟踪到db服务器时,我发现即使我只修改了一列,UPDATE也包含表中的所有列。例如— 我可以有5列的表,在客户端修改1,并调用SaveChanges()。 在服务器端,在oracle中 更新col1=x,col2=x,col3=x,col4=x,其中 我在网上读了很多关于这个问题的文章,但仍然没有找到任何明确的解决办法。当然,我不是唯一一个有这个

我有使用EF和Oracle Data Provider for.Net的OData服务(WCF Data Services 5.6)。 当我将查询从服务跟踪到db服务器时,我发现即使我只修改了一列,UPDATE也包含表中的所有列。例如— 我可以有5列的表,在客户端修改1,并调用SaveChanges()。 在服务器端,在oracle中

更新col1=x,col2=x,col3=x,col4=x,其中

我在网上读了很多关于这个问题的文章,但仍然没有找到任何明确的解决办法。当然,我不是唯一一个有这个问题的人,但可能有人知道如何解决这个问题 修好这个

我看到EF6很快就会出现,WCF数据服务团队为EF6发布了Alpha,但是,首先它仍然是alfa,EF6是RC,第二,它有一些问题,第三,不能保证新版本中不存在相同的问题


希望有人能给出正确的答案……

好的,看来我至少喜欢一种方法。 在WCF服务中,在ChangeInterceptor中:

  [ChangeInterceptor("Entity")]
        public void OnChange(Entity item, UpdateOperations operations)
        {
            Dictionary<string, object> changes = new Dictionary<string, object>();
            foreach (String propName in this.CurrentDataSource.Entry(item).CurrentValues.PropertyNames)
            {
                if (this.CurrentDataSource.Entry(item).Property(propName).IsModified)
                    changes.Add(propName, this.CurrentDataSource.Entry(item).Property(propName).CurrentValue);
            }
            this.CurrentDataSource.Entry(item).State = System.Data.EntityState.Unchanged;
            var arrayOfAllChangedProps = changes.Keys.ToArray();
            foreach(string prop in arrayOfAllChangedProps)
                this.CurrentDataSource.Entry(item).Property(prop).CurrentValue = changes[prop];
            return;
        }
[ChangeInterceptor(“实体”)]
更改后的公共void(实体项、更新操作)
{
字典更改=新字典();
foreach(此.CurrentDataSource.Entry(item).CurrentValues.PropertyNames中的字符串propName)
{
if(此.CurrentDataSource.Entry(item).Property(propName).IsModified)
添加(propName,this.CurrentDataSource.Entry(item).Property(propName).CurrentValue);
}
this.CurrentDataSource.Entry(item).State=System.Data.EntityState.Unchanged;
var arrayOfAllChangedProps=changes.Keys.ToArray();
foreach(ArrayFallChangedOps中的字符串属性)
this.CurrentDataSource.Entry(item).prop.CurrentValue=更改[prop];
返回;
}
我们得到修改后的值,将它们添加到字典(可以是任何其他集合),然后重置修改状态的标志。如果在此之前重置标志,则无法获得更改。重置标志时,在重置标志进行修改之前,将当前值设置为保存的值

在所有这些之后,我们将看到UPDATE语句中只有修改过的列


我真的不明白,为什么这不是默认行为?以及为什么所有这些魔法都应该被实现。另外,我不知道这是不是正确的方法。但至少对我来说,这是可行的。

今天,我刚刚使用EF5和DS5.6在测试数据集上生成了这个SQL查询:

exec sp_executesql N'update [dbo].[People]
set [City] = @0
where ([Id] = @1)
',N'@0 nvarchar(max) ,@1 bigint',@0=N'Mashville',@1=1
OData查询:
http://localhost:50000/People(1L)

OData有效载荷:
{“城市”:“Mashville”}

也许您忘记使用HTTP
PATCH
方法而不是
PUT