locked
EF 4 + WCF + POCO RRS feed

  • Question

  • I’m doing a test using WCF + Silverlight, I know that sometimes it would be easier with RiaServices but I want to try it with pure WCF.

     

    Here’s how my project is:

     

    Test.Servico : WCF Service

    Test.Dominio : Minhas Entidades POCO

    Test.Dados : Meus Repositórios e EDMX

     

    public void Salvar(T entidade)

            {

                using (var transacao = new TransactionScope())

                {

                    if (entidade.Id == 0)

                        Incluir(entidade);

                    else

                        Contexto.AttachTo(EntitySetName, entidade);

     

                    Contexto.SaveChanges();

                    transacao.Complete();

                }

            }

     

    I list the classes in Silverlight, include a new one, but when I try to modify an entity I can’t bring it back to the context, below you may see the code that saves the entity.

     

    Where is my mistake?

    Wednesday, April 14, 2010 8:31 PM

Answers

  • Hello,

     

    I remember we have met inthis thread.  Sorry I did not solve the problem.   But I hope I can help you in this case.  

     

    The MSDN documentationBuilding N-Tier Application (Entity Framework) introduces several methods to update entities in the scenario which is similar with yours.   One of them is usingObjectStateManager.ChangeObjectState method to set the entity’s state to Modified. 

    ==================================================================================================

           public void Salvar(T entidade)

           {

               using (var transacao = new TransactionScope())

               {

                   if (entidade.Id == 0)

                       Incluir(entidade);

                   else

                   {

                       Contexto.AttachTo(EntitySetName, entidade);

                       Contexto.ObjectStateManager.ChangeObjectState(entidade, EntityState.Modified);

                   }

                   Contexto.SaveChanges();

                   transacao.Complete();

               }

           }

    ==================================================================================================

     

    Does this method solve the problem?   If you have any questions, please feel free to let me know.

     

    Have a nice day!

     

     

    Best Regards,
    Lingzhi Sun

    MSDN Subscriber Supportin Forum

    If you have any feedback on our support, please contactmsdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Thursday, April 15, 2010 2:46 PM

All replies

  • Hello,

     

    I remember we have met inthis thread.  Sorry I did not solve the problem.   But I hope I can help you in this case.  

     

    The MSDN documentationBuilding N-Tier Application (Entity Framework) introduces several methods to update entities in the scenario which is similar with yours.   One of them is usingObjectStateManager.ChangeObjectState method to set the entity’s state to Modified. 

    ==================================================================================================

           public void Salvar(T entidade)

           {

               using (var transacao = new TransactionScope())

               {

                   if (entidade.Id == 0)

                       Incluir(entidade);

                   else

                   {

                       Contexto.AttachTo(EntitySetName, entidade);

                       Contexto.ObjectStateManager.ChangeObjectState(entidade, EntityState.Modified);

                   }

                   Contexto.SaveChanges();

                   transacao.Complete();

               }

           }

    ==================================================================================================

     

    Does this method solve the problem?   If you have any questions, please feel free to let me know.

     

    Have a nice day!

     

     

    Best Regards,
    Lingzhi Sun

    MSDN Subscriber Supportin Forum

    If you have any feedback on our support, please contactmsdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Thursday, April 15, 2010 2:46 PM
  • Yes, solve the problema, Thank you, thank you, thank you :D

     

    Thursday, April 15, 2010 4:29 PM
  • My pleasure!!!  :D

    Have a nice weekend!

     

     

    Best Regards,
    Lingzhi Sun

    MSDN Subscriber Supportin Forum

    If you have any feedback on our support, please contactmsdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Friday, April 16, 2010 1:21 AM
  • C# doesn't work in Spanish.
    Tuesday, October 16, 2012 12:12 AM