locked
Insert Two Linked Objects (together) RRS feed

  • Question

  • I have two entities A i B

    A  1----------*B

    I  create A
    I  cretae B

    How I link and save all (like a transaction) with Ado.Net DataServices?

    contex.savechanges, with option or no.

    Example:

    ......

     

    'tasca

     

    Dim etask As New Tasques

     

    'historic estats

     

    Dim estate As New CanviEstats

    estate.DataHora =

    Date.Now

     

    etask.Centre = centre.ID

    etask.DataHora =

    Date.Now

    etask.Descripcio = questio.Descripcio

     

    If questio.Impresora IsNot Nothing AndAlso questio.Impresora.Name IsNot Nothing Then

    etask.Impressora = questio.Impresora.Name

     

    End If

    etask.Maquina = questio.Maquina.Name

    etask.Uop = uop.ID

    etask.Usuari = ordre.Owner.Uid

    etask.Telefon = telefon.Number

     

     

    SyncLock (ctx)

    ctx.MergeOption = MergeOption.AppendOnly

    ctx.AddToTasques(etask)

    ctx.AddToCanviEstats(estate)

     

    'Questio

    ctx.SetLink(etask,

    "Questions", equestio)

    ctx.AddLink(equestio,

    "Tasques", etask)

     

     

    'Tecnic

    ctx.SetLink(etask,

    "Tecnics", etecnic)

    ctx.AddLink(etecnic,

    "Tasques", etask)

     

    'Prioritat

    ctx.SetLink(etask,

    "Prioritats", eprioritat)

    ctx.AddLink(eprioritat,

    "Tasques", etask)

     

    'subestat

    ctx.SetLink(etask,

    "SubEstats", esubestat)

    ctx.AddLink(esubestat,

    "Tasques", etask)

     

     

    ' HERE IS MY PROBLEM
    ctx.AddLink(etask, "CanviEstats", estate)

    ctx.SetLink(estate,

    "Tasques", etask)

    etask.CanviEstats.Add(estate)

     

    ' controlem sincronisme amb l'element compartit

     

    'molt important

     

    Try

    ' SAVE RETURNS ERROR


    ctx.SaveChanges()

     

    Catch ex As DataServiceRequestException

     

    'capture exception

     

    End Try

    ..........






    How I can make this with ADO Dataservices?

    Thanks




    Thursday, September 3, 2009 12:13 PM

Answers

  • If I understand this right , you need to change the SaveChanges() call to SaveChanges(SaveChangesOptions.Batch).
    This should work
    Phani Raj Astoria http://blogs.msdn.com/PhaniRaj
    Thursday, September 3, 2009 4:45 PM
    Moderator