This is a migrated thread and some comments may be shown as answers.

Basic CRUD Question for WCF Plain Services

1 Answer 40 Views
Web Services
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Steven
Top achievements
Rank 1
Steven asked on 13 Aug 2013, 11:07 PM
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

 

 

 

1 Answer, 1 is accepted

Sort by
0
Kristian Nikolov
Telerik team
answered on 14 Aug 2013, 01:15 PM
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.
Tags
Web Services
Asked by
Steven
Top achievements
Rank 1
Answers by
Kristian Nikolov
Telerik team
Share this question
or