仅一个字段不会在一个实体中更新 [英] A field alone does not updating in one entity

查看:95
本文介绍了仅一个字段不会在一个实体中更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在使用实体框架访问项目中的Db

在这里,我想通过单击更新按钮来更新两个实体(表)

Hi all,

i am using entity framework to access the Db in my project

here i want to update two entity(table) by clicking a update button

Dim xx As entityname = objContext.entityname.Where(Function(c) c.Rowid = intRowId And c.Type = intType).SingleOrDefault
If (true) Then
If Not IsNothing(xx) Then
xx.intrr = xx.intrr + intss
xx.intaa = xx.intaa - intpp
objContext.entityname.ApplyCurrentValues(xx)
objContext.SaveChanges()
End If

Dim yy As entityname1 = objContext.entityname1.Where(Function(d) d.Rowid = intRowId And d.Type = intType).SingleOrDefault

If Not IsNothing(yy) Then
yy.intxx = yy.xx + intyy
yy.inttt = yy.inttt - intss
objContext.entityname1.ApplyCurrentValues(yy)
objContext.SaveChanges()
End If

End If



以上表示要更新具有相同功能的两个实体

在这里,我可以更新entityname实体
而且我还能够更新实体名称1实体
但我无法仅更新entityname1中的一个字段(例如yy.inttt)

这样我就可以在SQL中看到表的设计,以检查默认的绑定值
因为没有绑定默认值的任何值

我做错了什么
请让我知道



the above denoting to update two entity in same functionality

here i can able to update the entityname entity
and i also can able to update the entityname 1 entity
but i cannot able to update only one field in entityname1 (for example yy.inttt)

so that i saw the design of the table in the SQL, to check the default binding values
since there is no anyvalue to bind default

what is the mistake done by me
please let me know

推荐答案

如果要更新整个对象图,则不需要ApplyCurrentValues.

http://msdn.microsoft.com/en-us/library/dd487246.aspx [ ^ ]
"ApplyCurrentValues(Of TEntity)方法用于将对ObjectContext之外的对象所做的更改应用于应用程序,例如Web服务接收的分离对象."

您没有分离的对象.
If you want to update the entire object graph then ApplyCurrentValues is not necessary.

http://msdn.microsoft.com/en-us/library/dd487246.aspx[^]
"The ApplyCurrentValues(Of TEntity) method is used to apply changes that were made to objects outside the ObjectContext, such as detached objects that are received by a Web service."

You don''t have a detached object.


这篇关于仅一个字段不会在一个实体中更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆