Reverse Mapping Problem

4 posts, 0 answers
  1. Teguh
    Teguh avatar
    12 posts
    Member since:
    Aug 2008

    Posted 18 Aug 2010 Link to this post

    Hi,

    I'm very new to this OpenAccess. I tried to do some reverse mapping using the wizard. And it works OK :)
    However, while trying to update a record which has property Contact object, the following error message is shown:

    Insert of '1794434107-b9019f15-9a1a-42bb-bdf2-5965bc399b30' failed: Telerik.OpenAccess.RT.sql.SQLException: Violation of PRIMARY KEY constraint 'PK_Contact'. Cannot insert duplicate key in object 'dbo.Contact'.
    The statement has been terminated.
       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 [Contact] ([ContactID], [CreationDate], [DOB], [EFY], [EmailAddress], [Fax], [FirstName], [HomePhone], [LastEditDate], [LastName], [MailOptOut], [MiddleName], [Mobile], [SpamOptOut], [Submitted], [TEMP_ConsID], [TEMP_EnjoID], [Title], [WorkPhone]) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
    (set event logging to all to see parameter values)

    Based on the error description, it looks like it tries to insert the Contact object. Is there something that I miss? Please kindly advice

    Following is the code snippet which being used to update the record:
    public string UpdateEntity<T>(T entity)
            {
                try
                {
                    string entityId = this.GetEntityId<T>(entity);
                    T existingObject = this.ReadEntity<T>(entityId);
                    this.ExecuteCopy(entity, existingObject);
                    this.scope.Transaction.Commit();
                    return entityId;
                }
                catch (Telerik.OpenAccess.OpenAccessException ex)
                {
                    this.RollBackTransaction(this.scope);
                    throw ex;
                }
            }

    Regards,
    Teguh Suryadi


  2. Damyan Bogoev
    Admin
    Damyan Bogoev avatar
    581 posts

    Posted 18 Aug 2010 Link to this post

    Hi Teguh,

    You should use one and the same IObjectScope instance for retrieving and editing an object. The IObjectScope manages the object’s state. If you try to use one scope for retrieving the object and later another for persisting the changes to the database the changes will not be saved and an exception will be thrown. 
    You could find the following help article useful for this topic. It demonstrates how to handle CRUD operations using Telerik OpenAccess ORM.
    Hope that helps. If any other questions arise, please do not hesitate to contact us back.


    Regards,
    Damyan Bogoev
    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
  4. Teguh
    Teguh avatar
    12 posts
    Member since:
    Aug 2008

    Posted 18 Aug 2010 Link to this post

    Hi Damyan,

    Thank you for the response and explanation.
    So how can we maintain the scope in the disconnected environment?
    Since we currently developing a web application using Sitefinity as its UI, and planing to use WCF service to communicate with the business layer.

    Please advice.

    Warm regards,
    Teguh Suryadi
  5. Damyan Bogoev
    Admin
    Damyan Bogoev avatar
    581 posts

    Posted 19 Aug 2010 Link to this post

    Hi Teguh,

    For disconnected web scenario you should use the ObjectContainer.  I recommend you reading the following help articles “Step 8: Disconnected API” and “How to: Use ObjectContainer as an alternative of the ObjectScope in ASP .NET with web services” which demonstrate the Disconnected API of Telerik OpenAccess.
    Additional helpful resources regarding the ObjectContainer can be found here and here.
    Hope that helps. If any other questions arise please contact us back.


    All the best,
    Damyan Bogoev
    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
Back to Top