one-to-many insert

2 posts, 0 answers
  1. Zbigniew Kozłowski
    Zbigniew Kozłowski avatar
    60 posts
    Member since:
    Apr 2010

    Posted 20 Apr 2010 Link to this post

    ive got table Contacts and second table ContactAddresses, ContactAddresses have reference to Contacts(in database) ive made in reverse mapping one-to-many so i have in Contacts collection of ContactAddresses. Ive got server app that makes transaction, and client app which creates contact object and send it over webservice to server app. it looks like:

    On server:
    public static string AddZus(Contact contact) 
        string Error = string.Empty; 
        IObjectScope scope = DBProvider.GetNewObjectScope(); 
        catch (Exception e) 
            Error = e.Message; 
        return Error; 

    On client:
    WebService.Contact contact = new WebService.Contact(); 
    WebService.Contactaddress[] contactAddresses = new WebService.Contactaddress[1]; 
    WebService.Contactaddress contactAddress = new WebService.Contactaddress(); 
    contact.Description = descriptionTextBox.Text; 
    contact.FullDescription = fullDescriptionTextBox.Text; 
    contact.Comments = commentTextBox.Text; 
    contactAddress.Address1 = address_1TextBox.Text; 
    contactAddress.Address2 = address_2TextBox.Text; 
    contactAddress.Address3 = address_3TextBox.Text; 
    contactAddress.City = cityTextBox.Text; 
    contactAddress.ContactAddressType = Enums.ContactAddressType.Main.ToString(); 
    contactAddress.Country = countryTextBox.Text; 
    contactAddress.Post = postTextBox.Text; 
    contactAddress.Status = Enums.Status.Active.ToString(); 
    contactAddress.ZipCode = zipCodeTextBox.Text; 
    contactAddresses[0] = contactAddress; 
    contact.Contactaddress = contactAddresses
    string Error = EasyCRMService.AddZUS(contact); 
    if (Error != string.Empty)MessageBox.Show(Error); 

    when it executes ive got error:

    Insert of '638682188-0' failed: Telerik.OpenAccess.RT.sql.SQLException: Column 'Contacts_ID' cannot be null 
       at Telerik.OpenAccess.RT.Adonet2Generic.Impl.PreparedStatementImp.execute() 
       at OpenAccessRuntime.Relational.conn.PooledPreparedStatement.execute() 
       at OpenAccessRuntime.Relational.RelationalStorageManager.generateInserts(NewObjectOID oid, Int32 index, ClassMetaData cmd, PersistGraph graph, Int32[] fieldNos, CharBuf s, Object[] oidData, IntArray toUpdateIndexes) 
    INSERT INTO `contactaddresses` (`ADDRESS_1`, `ADDRESS_2`, `ADDRESS_3`, `CITY`, `COMMENTS`, `Contacts_ID`, `CONTACT_ADDRESS_TYPE`, `COUNTRY`, `ID`, `POST`, `STATUS`, `ZIP_CODE`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) 
    (set event logging to all to see parameter values) Telerik.OpenAccess.RT.sql.SQLException: Column 'Contacts_ID' cannot be null 
       at Telerik.OpenAccess.RT.Adonet2Generic.Impl.PreparedStatementImp.execute() 
       at OpenAccessRuntime.Relational.conn.PooledPreparedStatement.execute() 
       at OpenAccessRuntime.Relational.RelationalStorageManager.generateInserts(NewObjectOID oid, Int32 index, ClassMetaData cmd, PersistGraph graph, Int32[] fieldNos, CharBuf s, Object[] oidData, IntArray toUpdateIndexes) 

    what im doing wrong? and how can i fix it?
  2. PetarP
    PetarP avatar
    754 posts

    Posted 22 Apr 2010 Link to this post

    Hello Zbigniew Kozłowski,

    Can you please open the forward mapping wizard and look in your Contact class for the property that represents your collection of ContactAddresses. Select that property and check if the Managed collection option is checked. If it is not please enable that option and rebuild your project. This should solve your problem.

    Please come back to us if that does not solve your problem.

    Sincerely yours,
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. DevCraft banner
Back to Top