Basic CRUD Question for WCF Plain Services

2 posts, 0 answers
  1. Steven
    Steven avatar
    1 posts
    Member since:
    Aug 2013

    Posted 13 Aug 2013 Link to this post

    I am building a n-tier app, and used the OpenAccess to generate the classes for my postgresql db.   On the client end, I retrieve a list DTO for one of my objects of type project (which is mapped eventually to a projects table).   I can retrieve a single project of type ProjectDto or retrieve List<ProjectDto> projects with no problem.   I retrieve them through the WCF Plain Web Services.   I am having a problem when trying to create a new Project item and persisting it.

    I tried the following:

    // This is the plain web service
    TestAdminServices.
    AdministrationServiceClient client = new TestAdminServices.AdministrationServiceClient();

    List<TestAdminServices.ProjectsDto> projs= client.ReadProjectses(); //return a list of current projects


    // Now create a new project
    TestAdminServices.
    ProjectsDto prj = new TestAdminServices.ProjectsDto();

    prj.Comments = "First Created by code";

    prj.CreationDate = DateTime.Now;

    prj.ModificationDate = prj.CreationDate;

    prj.DatabaseName = "IBET_Data";

    prj.MapName = "Hello Steve";

    prj.ProjectName = "IBEt_MAIN";

    // now persist it

    client.UpdateProjects(prj);  // <-  THIS GENERATES "An object key cannot be resolved from string" 

     

    How can I create a new project object and have it persist back to the database?    Any help or suggestions would be appreciated.

    Steve

     

     

     

  2. Kristian Nikolov
    Admin
    Kristian Nikolov avatar
    206 posts

    Posted 14 Aug 2013 Link to this post

    Hi Steven,

    The reason for the exception you are encountering is that the client.UpdateProjects() method is used to update a project which already exists in your database. In order to persist a new project in the database you need to use the Create method of the service, in your case CreateProjects(), which is present for each of your DTO`s.  The snippet below is based on the code you provided and illustrates how to persist a new Projects entity:
    TestAdminServices.AdministrationServiceClient client = new TestAdminServices.AdministrationServiceClient();
     
    TestAdminServices.ProjectsDto prj = new TestAdminServices.ProjectsDto();
     
    prj.Comments = "First Created by code";
     
    prj.CreationDate = DateTime.Now;
     
    prj.ModificationDate = prj.CreationDate;
     
    prj.DatabaseName = "IBET_Data";
     
    prj.MapName = "Hello Steve";
     
    prj.ProjectName = "IBEt_MAIN";
     
    //persisting the project
    client.CreateProjects(prj);

    You may also take a look at our Samples Kit. Under the tab N-Tier Development you will find detailed examples of WCF Plain Services integrated with both WPF and WinForms. The samples are named Sofia Car Rental - WCF Plain Services and Sofia Car Rental - WCF Plain Services with Windows Forms.

    I hope that helps.

    Regards,
    Kristian Nikolov
    Telerik
    OpenAccess ORM Q2 2013 brings you a more powerful code generation and a unique Bulk Operations support with LINQ syntax. Check out the list of new functionality and improvements shipped with this release.
  3. DevCraft banner
Back to Top