none
CRUD Silverligth tabela com relacionamentos RRS feed

  • Pergunta

  • Olá pessoal.. estou tentando sem sucesso um Update / Delete... O insert vai numa boa.

    Estou fazendo o insert ASSIM:

    this

     

    .newConferenceCurrent = new ConferenceCurrents
    {
    ProductQuantity =
    int.Parse(productQuantity.Text),
    IsNormalPackage = ckbPackage.IsChecked ==
    true ? true : false,
    ModifiedDate =
    DateTime.Now
    };

    contextConference.AddToConferenceCurrent(newConferenceCurrent);

    contextConference.SetLink(newConferenceCurrent, "Product", this.currentProduct);
    contextConference.SetLink(newConferenceCurrent,
    "OccurrenceType", this.currentOccurrenceType);
    contextConference.SetLink(newConferenceCurrent,
    "ConferenceStatus", this.currentConferenceStatus);

    contextConference.BeginSaveChanges(

    SaveChangesOptions.Batch,
    OnChangesSavedNewConferenceCurrent, contextConference);
    ==============

    No caso nessa tabela de Conferencia Corrente(ConferenceCurrent) tem relacionamentos com 3 tabelas:
    Tabela produtos(Product),
    Tabela Tipo de Ocorrencia(currentOccurrenceType),
    Tabela Status da conferencia(ConferenceStatus)

    Para o insert crio os novos valores em  newConferenceCurrent, pego os valores das buscas de produto, ocorrencia e status e repasso para currentProduct, currentOccurrenceType, currentConferenceStatus e dou o BeginSaveChanges..
    Blz.. funciona numa boa.. os novos valores junto aos relacionamentos...


    Mais para fazer um update do campo IsNormalPackage ou campo ProductQuantity da tabela ConferenceCurrent???
    Podem ajudar já tentei diversas formas seguindo os links abaixo e não esta dando certo... Dá erro e o VS2008 Fecha.

    http://msdn.microsoft.com/en-us/library/cc903956%28VS.95%29.aspx
    http://www.experts-exchange.com/Microsoft/Development/Microsoft_Programming/WPF_and_Silverlight/Q_23819515.html
    http://www.codeproject.com/KB/silverlight/crud-op-in-silverlight.aspx?msg=2434062

    Estou usando. ADO.Data Services, Entity Framework e Silverlight

    Agradeceria muito..


    quarta-feira, 11 de novembro de 2009 19:15

Respostas

  • Tentei desta forma também...
    Ele passa sem erros. mais não atualiza o FK, somente o campo ModifiedDate 

     

     

    [ Member Variables ]
    private ConferenceEntities contextConferenceOverwrite;
    private InvoiceNoteCurrents currentInvoiceNoteCurrent;
    private
    InvoiceNoteStatuss currentInvoiceNoteStatus;
    private DataServiceQuery<InvoiceNoteStatuss> queryInvoiceNoteStatus;

     

    [ LOAD ]
    this.contextConferenceOverwrite = new ConferenceEntities(new Uri("http://localhost:1466/services/ConferenceService.svc", UriKind.RelativeOrAbsolute));
    this.contextConferenceOverwrite.MergeOption = MergeOption.OverwriteChanges;

    [ UPDATE ]


     

    string filterExpressionInvoiceNoteStatus = "Name eq 'Conferido'";
    this.queryInvoiceNoteStatus = contextConference.InvoiceNoteStatus.AddQueryOption("$filter",filterExpressionInvoiceNoteStatus);
    this.queryInvoiceNoteStatus.BeginExecute(OnInvoiceNoteStatusQueryComplete, this.queryInvoiceNoteStatus);

    private

     

    void OnInvoiceNoteStatusQueryComplete(IAsyncResult result)
    {
         DataServiceQuery<InvoiceNoteStatuss> query = result.AsyncState as DataServiceQuery<InvoiceNoteStatuss>;
         InvoiceNoteStatuss returnedInvoiceNoteStatus = query.EndExecute(result).FirstOrDefault();
         if (returnedInvoiceNoteStatus != null)
         {

             this.currentInvoiceNoteStatus = returnedInvoiceNoteStatus;
             
             contextConferenceOverwrite.AttachTo("InvoiceNoteCurrent", this.currentInvoiceNoteCurrent); 
             this.currentInvoiceNoteCurrent.ModifiedDate = DateTime.Now;

             contextConferenceOverwrite.AttachTo(
    "InvoiceNoteStatus", this.currentInvoiceNoteStatus);
             this.currentInvoiceNoteCurrent.InvoiceNoteStatus = this.currentInvoiceNoteStatus;

             contextConferenceOverwrite.UpdateObject(this.currentInvoiceNoteCurrent);
             contextConferenceOverwrite.BeginSaveChanges(
    SaveChangesOptions.ReplaceOnUpdate, OnChangesSaved, contextConferenceOverwrite);  
        
         }
    }

     

    private void OnChangesSaved(IAsyncResult result)
    {
        Dispatcher.BeginInvoke(() =>
        {
             contextConferenceOverwrite = result.AsyncState
    as ConferenceEntities;
             DataServiceResponse response = contextConferenceOverwrite.EndSaveChanges(result);
             if (response == null)
             {
                  throw new DataServiceQueryException("Erro xxxxxx!!!");
             }

         });
    }

    • Marcado como Resposta Daniel Ferreira quarta-feira, 14 de julho de 2010 13:37
    quinta-feira, 12 de novembro de 2009 20:36

Todas as Respostas

  • Olá Pessoal, consegui fazer update desta forma(codigo abaixo).. mais apenas alguns campos..
    Não consegui ainda atualizar campos de relacionamento... Alguém sabe como faço isso.

    ConferenceEntities contextConferenceOverwrite =

    new ConferenceEntities(new Uri("http://localhost:1466/services/ConferenceService.svc", UriKind.RelativeOrAbsolute));
    contextConferenceOverwrite.MergeOption =
    MergeOption.OverwriteChanges;

    private

     

    DataServiceQuery<InvoiceNoteCurrents> queryInvoiceNoteCurrent;
    private InvoiceNoteCurrents currentInvoiceNoteCurrent;

     

     

     

    queryInvoiceNoteCurrent = (from ...) as DataServiceQuery<InvoiceNoteCurrents>; // Linq
    .
    . === Chamada
    .
    this.currentInvoiceNoteCurrent =  queryInvoiceNoteCurrent .EndExecute(result);

    #atualizar click ===============================

    contextConferenceOverwrite.AttachTo(

    "InvoiceNoteCurrent", this.currentInvoiceNoteCurrent);
    this.currentInvoiceNoteCurrent.ModifiedDate = DateTime.Now;
    // Como atualizar um FK??? eX STATUS NoteCurrentid LINCADO Com a tabela de status???


    contextConferenceOverwrite.UpdateObject(

    this.currentInvoiceNoteCurrent);
    contextConferenceOverwrite.BeginSaveChanges(
    SaveChangesOptions.ReplaceOnUpdate,
    OnChangesSavedUpdateInvoiceNoteCurrent, contextConferenceOverwrite);

    quinta-feira, 12 de novembro de 2009 01:38
  • Olá pessoal... alguém sabe, já passou por isso.. Ajuda!!!

    Como faço uma atualização em FK de uma tabela????

    Ex:
    Tenho tabelas de InvoiceNoteCurrent e InvoiceNoteCurrentStatus.. 
    na tabela InvoiceNoteCurrent tenho vinculo com a tabela InvoiceNoteCurrentStatus.. pelo campo InvoiceNoteCurrentID.
    ..

    Se eu tenho seguintes resultados. nas tabelas
    Tabela InvoiceNoteCurrent
    ==========================================
    Name     | InvoiceNoteCurrentID  ModifiedDate             |
    ----------------------------------------------------------------------------
    produto1 | 1                                    | 2009-11-12 00:01:02.627
    produto2 | 1                                    | 2009-11-12 00:01:04.444
    produto3 | 3                                    | 2009-11-12 00:01:07.607
    produto4 | 2                                    | 2009-11-12 00:01:02.627
    ==========================================

    Tabela InvoiceNoteCurrentStatus
    ======================
    InvoiceNoteCurrentID | Name
    ---------------------------------------
                   1                    | Aberto
                   2                    | Conferido
                   3                    | Divergencia
    ======================


    Como atualizar a tabela InvoiceNoteCurrent.. trocando o InvoiceNoteCurrentID do produto3 de 3 para 1??????

    Consigo atualizar qualquer campo na tabela com o codigo abaixo.. no qual atualizo o campo data, Mais não consigo alterar O fk...InvoiceNoteCurrentID
    TENTEI COM SETLINK mais sem sucesso...Já estou p...


    contextConferenceOverwrite.AttachTo(

    "InvoiceNoteCurrent", this.currentInvoiceNoteCurrent);
    this.currentInvoiceNoteCurrent.ModifiedDate = DateTime.Now;

    contextConferenceOverwrite.UpdateObject(

    this.currentInvoiceNoteCurrent);
    contextConferenceOverwrite.BeginSaveChanges(
    SaveChangesOptions.ReplaceOnUpdate,
    OnChangesSavedUpdateInvoiceNoteCurrent, contextConferenceOverwrite);

    TEntei sem sucesso Assim mais da erro:

    contextConferenceOverwrite.AttachTo(

    "InvoiceNoteStatus", this.currentInvoiceNoteStatus);

    //currentInvoiceNoteStatus = resultado da query ado.dataservices com status da alterao


    contextConferenceOverwrite.AttachTo(

     


    contextConferenceOverwrite.AttachTo(


    contextConferenceOverwrite.AttachTo(

    "InvoiceNoteCurrent", this.currentInvoiceNoteCurrent);
    this.currentInvoiceNoteCurrent.ModifiedDate = DateTime.Now;

    contextConferenceOverwrite.SetLink(
    this.currentInvoiceNoteCurrent, "InvoiceNoteStatus", this.currentInvoiceNoteStatus);
    contextConferenceOverwrite.UpdateObject(
    this.currentInvoiceNoteCurrent);
    contextConferenceOverwrite.BeginSaveChanges(
    SaveChangesOptions.ReplaceOnUpdate,
    OnChangesSavedUpdateInvoiceNoteCurrent, contextConferenceOverwrite);

    da erro quando vai salvar....




    quinta-feira, 12 de novembro de 2009 19:12
  • Tentei desta forma também...
    Ele passa sem erros. mais não atualiza o FK, somente o campo ModifiedDate 

     

     

    [ Member Variables ]
    private ConferenceEntities contextConferenceOverwrite;
    private InvoiceNoteCurrents currentInvoiceNoteCurrent;
    private
    InvoiceNoteStatuss currentInvoiceNoteStatus;
    private DataServiceQuery<InvoiceNoteStatuss> queryInvoiceNoteStatus;

     

    [ LOAD ]
    this.contextConferenceOverwrite = new ConferenceEntities(new Uri("http://localhost:1466/services/ConferenceService.svc", UriKind.RelativeOrAbsolute));
    this.contextConferenceOverwrite.MergeOption = MergeOption.OverwriteChanges;

    [ UPDATE ]


     

    string filterExpressionInvoiceNoteStatus = "Name eq 'Conferido'";
    this.queryInvoiceNoteStatus = contextConference.InvoiceNoteStatus.AddQueryOption("$filter",filterExpressionInvoiceNoteStatus);
    this.queryInvoiceNoteStatus.BeginExecute(OnInvoiceNoteStatusQueryComplete, this.queryInvoiceNoteStatus);

    private

     

    void OnInvoiceNoteStatusQueryComplete(IAsyncResult result)
    {
         DataServiceQuery<InvoiceNoteStatuss> query = result.AsyncState as DataServiceQuery<InvoiceNoteStatuss>;
         InvoiceNoteStatuss returnedInvoiceNoteStatus = query.EndExecute(result).FirstOrDefault();
         if (returnedInvoiceNoteStatus != null)
         {

             this.currentInvoiceNoteStatus = returnedInvoiceNoteStatus;
             
             contextConferenceOverwrite.AttachTo("InvoiceNoteCurrent", this.currentInvoiceNoteCurrent); 
             this.currentInvoiceNoteCurrent.ModifiedDate = DateTime.Now;

             contextConferenceOverwrite.AttachTo(
    "InvoiceNoteStatus", this.currentInvoiceNoteStatus);
             this.currentInvoiceNoteCurrent.InvoiceNoteStatus = this.currentInvoiceNoteStatus;

             contextConferenceOverwrite.UpdateObject(this.currentInvoiceNoteCurrent);
             contextConferenceOverwrite.BeginSaveChanges(
    SaveChangesOptions.ReplaceOnUpdate, OnChangesSaved, contextConferenceOverwrite);  
        
         }
    }

     

    private void OnChangesSaved(IAsyncResult result)
    {
        Dispatcher.BeginInvoke(() =>
        {
             contextConferenceOverwrite = result.AsyncState
    as ConferenceEntities;
             DataServiceResponse response = contextConferenceOverwrite.EndSaveChanges(result);
             if (response == null)
             {
                  throw new DataServiceQueryException("Erro xxxxxx!!!");
             }

         });
    }

    • Marcado como Resposta Daniel Ferreira quarta-feira, 14 de julho de 2010 13:37
    quinta-feira, 12 de novembro de 2009 20:36