Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Framework entity
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
 
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 15-Feb-12 2:10am
Edited 15-Feb-12 9:13am
v3
Comments
Mark Nischalke at 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 at 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 at 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

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 277
1 Maciej Los 210
2 BillWoodruff 195
3 DamithSL 195
4 Richard MacCutchan 178
0 OriginalGriff 5,130
1 DamithSL 4,197
2 Maciej Los 3,670
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,821


Advertise | Privacy | Mobile
Web04 | 2.8.141216.1 | Last Updated 16 Feb 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100