Click here to Skip to main content
16,007,932 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

VB
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


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
Posted
Updated 15-Feb-12 8:13am
v3
Comments
[no name] 15-Feb-12 11:26am    
It isn't very clear. Do you only want the field yy.inttt to be updated, and no other field on this entity?
msk kumar 16-Feb-12 1:54am    
Hi Mark
I need to update two entities(tables), enatityname and entityname1 also
ok
in entityname entity
xx.intrr = xx.intrr + intss
xx.intaa = xx.intaa - intpp
this want to update

similarly
in entityname1 entity also want to update the following two fields
yy.intxx = yy.xx + intyy
yy.inttt = yy.inttt - intss
Here the field yy.inttt is only not updating (stay remains the same value in the DB)
but yy.inttxx is updating fine

i think it is clear now
thank you
Kreagan Naicker 15-Feb-12 14:18pm    
I'm with Mark on this one, i'm not sure what you require assistance with.

If i literally translation your request, then you only what to update the variable yy.inttt, if this is the case then simply remove the following statement:
yy.intxx = yy.xx + intyy

This should result in only the yy.inttt variable being updated.

1 solution

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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900