It seems that EEO is another table having relationship with ds,and the relationship might be set with something like Cascading Updating……please check it。
Ok ... I understand that. What if I'm not using a formCollection?
Here is the function:
public string int recordStatus() //this is called via AJAX from an ASPX page
{
DEVEntities1 dbcontext = new DEVEntities1();
dataSheet ds = dbcontext.dataSheets.SingleOrDefault(d => d.UID == UID); //UID comes from querystring via ajax
ds.taxJurisdiction.docID = 4; //taxJurisdiction is an association of dataSheet (1 to 0..1), foreign key set to do nothing on update,
//at this point in debug I have a valid ds and taxJurisdiction object (i can see in watch) ..
//note that I set ds.taxJurisdiction.docID = 4 NOT ds.docID = 4 (ds also has a docID property)
UpdateModel(ds);
dbcontext.SaveChanges();
}
The code above updates the taxJurisdiction table with a docID of 4 BUT!!! .. it also updates the dataSheet table (ds) with a docID of 4
both tables have a docID field/property.
I only want the taxJurisdiction entity to update but for some reason the changes or updates are propogating down to the datasheet.
As far as I see,I don't think that's a problem related with UpdateModel。Even if you don't write FormCollection,and it will try to update model by using FormCollection and find out the property of FormCollections' names and assign to the model instance。
parandal1
Member
262 Points
212 Posts
Need Help! Association root problem
Feb 02, 2012 02:19 PM|LINK
I have a root entity called dataSheet that has one association entity called EEO. I get the datasheet like this:
DEVEntities1 dbcontext = new DEVEntities1();
dataSheet ds = dbcontext.dataSheets.SingleOrDefault(d => d.UID == formID);
so now I can type ds.EEO right?
That works so I set ds.EEO.docID = 4
and then I do a updateModel(ds)
and then I do a dbcontext.savechanges()
this all works as well with one exception
not only is the EEO entity (docID property) updating in the db
the ds entity (which also has a docID property on it) is also updating.
I want to update ds.EEO.docID
not ds.docID
How is ds.docID updating when I specifically
tell ds.EEO.docID to update?
Any help?
parandal1
Member
262 Points
212 Posts
Re: Need Help! Association root problem
Feb 02, 2012 03:55 PM|LINK
No one can help? This can't be default behavior for EF ... if so I would be surprised.
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Need Help! Association root problem
Feb 04, 2012 02:03 AM|LINK
It seems that EEO is another table having relationship with ds,and the relationship might be set with something like Cascading Updating……please check it。
Reguards。
parandal1
Member
262 Points
212 Posts
Re: Need Help! Association root problem
Feb 06, 2012 02:17 PM|LINK
I checked the option to cascade updates on the foreign key and it is set to none.
My original code has "updateModel(ds)" then "context.saveChanges()"
I removed the "updateModel(ds)" code and now everything is working correctly.
I guess I don't understand the difference between what updateModel is doing vs. saveChanges.
I will need to research this.
thanks
</div>Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Need Help! Association root problem
Feb 06, 2012 11:57 PM|LINK
updataModel means it will get all the values from formCollections' parameters and assign to the mapping properties of a specific instance。
SaveChanges will save the newly-built instance into db。
Reguards!
parandal1
Member
262 Points
212 Posts
Re: Need Help! Association root problem
Feb 07, 2012 05:07 PM|LINK
Ok ... I understand that. What if I'm not using a formCollection?
Here is the function:
public string int recordStatus() //this is called via AJAX from an ASPX page
{
DEVEntities1 dbcontext = new DEVEntities1();
dataSheet ds = dbcontext.dataSheets.SingleOrDefault(d => d.UID == UID); //UID comes from querystring via ajax
ds.taxJurisdiction.docID = 4; //taxJurisdiction is an association of dataSheet (1 to 0..1), foreign key set to do nothing on update,
//at this point in debug I have a valid ds and taxJurisdiction object (i can see in watch) ..
//note that I set ds.taxJurisdiction.docID = 4 NOT ds.docID = 4 (ds also has a docID property)
UpdateModel(ds);
dbcontext.SaveChanges();
}
The code above updates the taxJurisdiction table with a docID of 4 BUT!!! .. it also updates the dataSheet table (ds) with a docID of 4
both tables have a docID field/property.
I only want the taxJurisdiction entity to update but for some reason the changes or updates are propogating down to the datasheet.
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Need Help! Association root problem
Feb 08, 2012 12:26 AM|LINK
As far as I see,I don't think that's a problem related with UpdateModel。Even if you don't write FormCollection,and it will try to update model by using FormCollection and find out the property of FormCollections' names and assign to the model instance。
parandal1
Member
262 Points
212 Posts
Re: Need Help! Association root problem
Feb 08, 2012 01:36 AM|LINK
I am sorry but I'm not sure that I understand what you are saying.
I basically have a context, and two objects that are related. I only want the one entity (the association) to be updated.
Any more help?
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Need Help! Association root problem
Feb 08, 2012 01:52 AM|LINK
Hello again:)
Have you set Cascading Updating for the database?Please open your SQL db to see what's relationship setting between your tables?
Reguards!
parandal1
Member
262 Points
212 Posts
Re: Need Help! Association root problem
Feb 08, 2012 08:31 PM|LINK
The cascade on update is set to "do nothing" or "none" ... I forget what it actually states. Cascading update is turned off.
This seems so simple to do but it is not working as I would expect.
Anyone?