Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to update non-scalar entity properties in EF 4.0?
    primarykey
    data
    text
    <p>At first I was using this as an extension method to update my detached entities...</p> <pre><code>Public Sub AttachUpdated(ByVal obj As ObjectContext, ByVal objectDetached As EntityObject) If objectDetached.EntityState = EntityState.Detached Then Dim original As Object = Nothing If obj.TryGetObjectByKey(objectDetached.EntityKey, original) Then obj.ApplyCurrentValues(objectDetached.EntityKey.EntitySetName, objectDetached) Else Throw New ObjectNotFoundException() End If End If End Sub </code></pre> <p>Everything has been working great until I had to update non-scalar properties. Correct me if I am wrong but that is because "ApplyCurrentValues" only supports scalars. To get around this I was just saving the FK_ID field instead of the entity object relation. Now I am faced with a many to many relationship so its not that simple. I would like to do something like this...</p> <pre><code>Dim Resource = RelatedResource.GetByID(item.Value) Condition.RelatedResources.Add(Resource) </code></pre> <p>But when I call SaveChanges the added Resources aren't saved. I started to play around with self-tracking entities (not sure if they will help solve my prob) but it seems they cannot be serialized to ViewState and this is a requirement for me.</p> <p>I guess one solution would be to add the xRef table as an entity and add the fks myself but I would rather it just work how I expect it too.</p> <p>I am open to any suggestions on how to either save my many to many relationships or serialize self-tracking entities (if self-trackingwould even solve my problem). Thanks!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload