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

one-to-many insert

1 Answer 63 Views
Getting Started
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Zbigniew Kozłowski
Top achievements
Rank 1
Zbigniew Kozłowski asked on 20 Apr 2010, 12:10 PM
Hi,
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(); 
 
    scope.Transaction.Begin(); 
    scope.Add(contact); 
 
    try 
    { 
        scope.Transaction.Commit(); 
    } 
    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?

1 Answer, 1 is accepted

Sort by
0
PetarP
Telerik team
answered on 22 Apr 2010, 04:21 PM
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,
Petar
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.
Tags
Getting Started
Asked by
Zbigniew Kozłowski
Top achievements
Rank 1
Answers by
PetarP
Telerik team
Share this question
or