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

Reverse Mapping Problem

3 Answers 75 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.
Teguh
Top achievements
Rank 1
Teguh asked on 18 Aug 2010, 09:52 AM
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


3 Answers, 1 is accepted

Sort by
0
Damyan Bogoev
Telerik team
answered on 18 Aug 2010, 04:44 PM
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
0
Teguh
Top achievements
Rank 1
answered on 19 Aug 2010, 02:30 AM
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
0
Damyan Bogoev
Telerik team
answered on 19 Aug 2010, 05:10 PM
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
Tags
Getting Started
Asked by
Teguh
Top achievements
Rank 1
Answers by
Damyan Bogoev
Telerik team
Teguh
Top achievements
Rank 1
Share this question
or