简体   繁体   中英

Can't get the ApplyCurrentValues(Entity) to work

Im working on the update section for my application , i want to use the ApplyCurrentValues but it seems not working(unknown)

Dim e = (From o In x.Concours Where o.numero_concours = concours.numero_concours Select o).FirstOrDefault()
x.ApplyCurrentValues(e.EntityKey.EntitySetName,concours) x.savechanges()

in order to make it work I've changed the code to this :

 x.Concours.Attach(New Concour With {.numero_concours = concours.numero_concours})
        Dim e = New Concour With {.numero_concours = concours.numero_concours}
        x.Entry(concours).CurrentValues.SetValues(e)
        x.SaveChanges()

but it gives me this error

Can not call member 'CurrentValues​​' for entity type 'Concour' because the entity does not exist in the context. To add an entity to the context, call the Add method of DbSet or Attach.

so, i've used instead this :

 Dim e = (From o In x.Concours Where o.numero_concours = concours.numero_concours Select o).FirstOrDefault()
        x.Concours.Attach(New Concour With {.numero_concours = e.numero_concours})
        ((IObjectContextAdapter)x).ObjectContext.ApplyCurrentValues("Conours", e)

        x.SaveChanges()

but it's giving me a syntax error on the ((IobjectContext..... any suggestions please !!!


 Public Sub UpdateConcours(concours As Concour) Implements IConcoursRepository.UpdateConcours


      Dim e = (
From o In x.Concours
Where o.numero_concours = concours.numero_concours
Select o)
.First()
x.Entry(e)
.OriginalValues
.SetValues(concours)
       x.SaveChanges()
    End Sub

Try this:

Dim e = (
    From o In x.Concours
    Where o.numero_concours = concours.numero_concours
    Select o)
    .First()

x.Entry(e)
    .OriginalValues
    .SetValues(concours)

x.ChangeTracker.DetectChanges();

x.savechanges()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM