1:1 saving

Posts   
 
    
griZZZly
User
Posts: 10
Joined: 06-Aug-2008
# Posted on: 06-Aug-2008 10:48:04   

Hello. I have two tables with 1:1 relationship (ParserSourceSection & ParserSourceSectionTemplate). I am creating this entities.

            ParserSourceSectionEntity section = new ParserSourceSectionEntity();
            section.Name = "qwerty";

            adapter.SaveEntity(section, true);

            ParserSourceSectionTemplateEntity template = new ParserSourceSectionTemplateEntity(section.Id);
            adapter.SaveEntity(template, true);

At the last save i have ORMQueryConstructorException "The insert query doesn't contain any fields."

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 06-Aug-2008 11:08:58   

The PK passed in the CTor is not used fo inserts (new entity). To insert a new entity, you should use the parameterless CTor.

Please try the following:

ParserSourceSectionTemplateEntity template = new ParserSourceSectionTemplateEntity();
template.SectionId = section.Id;
adapter.SaveEntity(template, true);
griZZZly
User
Posts: 10
Joined: 06-Aug-2008
# Posted on: 06-Aug-2008 11:42:42   

I changed my code. You method is not works (the same error). But then i see - ParserSourceSectionTemplate.Id is readonly. Now i set readonly to false and ypu method works. Thank you. Now, can you tell me, maybe i shouldn't do this?

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 06-Aug-2008 12:04:36   

Please check the Designer for the properties of this field, most probably it was flagged to be an identity column (which automatically flags the readonly flag), or just flagged to be Readonly. If you uncheck either of these in the designer you should be set.

griZZZly
User
Posts: 10
Joined: 06-Aug-2008
# Posted on: 06-Aug-2008 12:13:30   

Thank you. Topic closed.