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

Web API CRUD with Kendo

5 Answers 93 Views
Web Services
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Guy
Top achievements
Rank 1
Guy asked on 03 Apr 2013, 02:58 PM
Hi,

I have been trying to re-create the tutorial ASP.Net Web API from the quick start scenario.
Is it just me or does the delete not work?

I receive a:
<STRONG><EM>Object references between two different object scopes are not 
allowed. The object 'CarRentWebSite.Category' is already managed by 
'ObjectScopeImpl 0x4' and was tried to be managed again by 'ObjectScopeImpl 0x3 
OpenAccessRuntime.EnlistableObjectScope'.</EM></STRONG>


Kind regards,

Guy

5 Answers, 1 is accepted

Sort by
0
Accepted
Dimitar Tachev
Telerik team
answered on 08 Apr 2013, 09:52 AM
Hi Guy,

 
In general this exception is thrown when a persistent object is managed by more than one context instances without detaching and reattaching the entity.

I tried to reproduce this behavior with the ASP.NET Web API quick start scenario but everything was working property - please find the project attached.

Could you please provide us with more details about the scenario where you are getting this issue and whether you have made any changes of the code from the Delete and GetBy methods of the OpenAccessBaseRepository which could be the reason for getting this exception?

I am looking forward to your feedback.

Kind regards,
Dimitar Tachev
the Telerik team
Using Encrypted Connection Strings with Telerik OpenAccess ORM. Read our latest blog article >>
0
Guy
Top achievements
Rank 1
answered on 08 Apr 2013, 11:20 AM
Hi Dimitar,

Thanks for your reply.

After comparing the 2 projects, yours and mine, I noticed that there is a difference in OpenAccessBaseRepository.cs

Old version:
Public Overridable Function AddNew(entity As TEntity) As TEntity Implements IOpenAccessBaseRepository(Of TEntity, TContext).AddNew
            If entity Is Nothing Then
                Throw New ArgumentNullException("entity")
            End If
 
            Dim attachedEntity As TEntity = dataContext.AttachCopy(entity)
            dataContext.SaveChanges()
 
            Return attachedEntity
        End Function
 
        Public Overridable Function Update(entity As TEntity) As TEntity Implements IOpenAccessBaseRepository(Of TEntity, TContext).Update
            If entity Is Nothing Then
                Throw New ArgumentNullException("entity")
            End If
 
            Dim attachedEntity As TEntity = dataContext.AttachCopy(entity)
            dataContext.SaveChanges()
 
            Return attachedEntity
        End Function
 
        Public Overridable Sub Delete(entity As TEntity) Implements IOpenAccessBaseRepository(Of TEntity, TContext).Delete
            If entity Is Nothing Then
                Throw New ArgumentNullException("entity")
            End If
 
            dataContext.Delete(entity)
            dataContext.SaveChanges()
        End Sub
 
    End Class

Your version:
Public Overridable Function AddNew(entity As TEntity) As TEntity Implements IOpenAccessBaseRepository(Of TEntity, TContext).AddNew
            If entity Is Nothing Then
                Throw New ArgumentNullException("entity")
            End If
 
            Dim attachedEntity As TEntity = dataContext.AttachCopy(entity)
            dataContext.SaveChanges()
            Dim detachedEntity As TEntity = dataContext.CreateDetachedCopy(attachedEntity, fetchStrategy)
 
            Return detachedEntity
        End Function
 
        Public Overridable Function Update(entity As TEntity) As TEntity Implements IOpenAccessBaseRepository(Of TEntity, TContext).Update
            If entity Is Nothing Then
                Throw New ArgumentNullException("entity")
            End If
 
            Dim attachedEntity As TEntity = dataContext.AttachCopy(entity)
            dataContext.SaveChanges()
            Dim detachedEntity As TEntity = dataContext.CreateDetachedCopy(attachedEntity, fetchStrategy)
 
            Return detachedEntity
        End Function
 
        Public Overridable Sub Delete(entity As TEntity) Implements IOpenAccessBaseRepository(Of TEntity, TContext).Delete
            If entity Is Nothing Then
                Throw New ArgumentNullException("entity")
            End If
            Dim attachedEntity As TEntity = dataContext.AttachCopy(entity)
            dataContext.Delete(attachedEntity)
            dataContext.SaveChanges()
        End Sub

Kind regards,

Guy
0
Accepted
Dimitar Tachev
Telerik team
answered on 11 Apr 2013, 06:56 AM
Hi Guy,

Thank you for the provided details.

The difference between the versions is caused by an issue in the Delete method of the Web API Service code generation which is already fixed and you could find it updated in the latest internal build of Telerik OpenAccess ORM.

You could download it from: Your Account page -> Manage products menu -> Latest internal builds -> product: OpenAccess ORM  version: 2013.1.219 -> Telerik-OpenAccess-ORM-2013.1.404.2.msi.
 

Greetings,
Dimitar Tachev
the Telerik team
Using Encrypted Connection Strings with Telerik OpenAccess ORM. Read our latest blog article >>
0
Guy
Top achievements
Rank 1
answered on 12 Apr 2013, 10:12 AM
Hi Dimitar,

I will try to follow these guidelines now to create a web api on our database.
Do I need to set some specific parameters in SQL Server 2008 R2 to use a web api?

Kind regards,

Guy
0
Accepted
Dimitar Tachev
Telerik team
answered on 12 Apr 2013, 11:28 AM
Hi Guy,

There aren't any specific settings of the SQL Server for generating the Web API services. You could just follow the Add OpenAccess Service Wizard which will set all of the necessary configurations for you.

Do not hesitate to contact us back if you need any further assistance.

Kind regards,
Dimitar Tachev
the Telerik team
Using Encrypted Connection Strings with Telerik OpenAccess ORM. Read our latest blog article >>
Tags
Web Services
Asked by
Guy
Top achievements
Rank 1
Answers by
Dimitar Tachev
Telerik team
Guy
Top achievements
Rank 1
Share this question
or