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

Detached Objects have no properties on client side

5 Answers 84 Views
Data Access Free Edition
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Michael
Top achievements
Rank 1
Michael asked on 31 Jan 2013, 03:25 PM
We have a client-server application that use Zyan as Communications Layer. That works fine with own Objects and lists

Now we want transfer a detached object from server to client. But on Client side the properties of the enties in the list are empty.

We found out that on server side the List is filled but the backing fields are empty. If we debugging the code and show the entity on the server first then the client entity is successfull created.

Here our code
Public Function Get50Contacts() As List(Of Contact) Implements IContacts.Get50Contacts
 
       Dim context As New dmContacts
       Dim tmpList As IQueryable(Of Contact) = context.Contacts.Skip(10).Take(50)
 
       Dim detachedList As New List(Of Contact)
 
       For Each loopContact As Contact In tmpList
           detachedList.Add(context.CreateDetachedCopy(loopContact))
       Next
 
       Return detachedList
 
   End Function

What is missin on the server side?

5 Answers, 1 is accepted

Sort by
0
Dimitar Tachev
Telerik team
answered on 01 Feb 2013, 02:59 PM
Hello Michael,

In general when you detach some entities without specifying a fetch strategy it is using the default one which does a flat detach without considering any reference fields. In order to get the associated entities along with the Contact one you could easily specify your custom fetch strategy.

For your convenience I prepared a code snipped demonstrating that approach on the Orders table from the Northwind database. With the following FetchStrategy along with the Order entities we will also get their Customer and Employee fields populated.

Public Function Get50Orders() As List(Of Order)
    Dim strategy As New FetchStrategy()
    strategy.LoadWith(Of Order)(Function(o) o.Customer, Function(o) o.Employee)
 
    Dim context As New EntitiesModel
    Dim allOrders As List(Of Order) = context.Orders.Skip(10).Take(50).ToList()
 
    Dim detachedList As New List(Of Order)
 
    detachedList =
          context.CreateDetachedCopy(Of List(Of Order))(allOrders, strategy)
 
    Return detachedList
End Function

Also you could take a look at this documentation section where you could find more information about detaching objects from the OpenAccess context.
 
I hope this helps. Do not hesitate to contact us back if you need any further assistance.

Regards,
Dimitar Tachev
the Telerik team
Q3'12 SP1 of OpenAccess ORM packs Multi-Table Entities mapping support. Check it out.
0
Michael
Top achievements
Rank 1
answered on 02 Feb 2013, 08:16 AM
Thank you very much for your comment. But I think that is not our main problem what I try to describe.

We have investige some issues with the detaching of objects.

1. If I create a detached copy of my data then the data is only possible to transfer if we loop and preserialize it (I found the hint here http://www.telerik.com/community/forums/orm/general-discussions/serialization-and-eager-loading.aspx).

2. Our list with the result from the query is fine. All Now we want to transfer it to the client. We detach it and then the objects of the subentries are not anymore unique. After the detaching the objectgraph is detroyed. Did you know a way that we can transfer our data to use on client-side with the objectgraph?

Thanks for your comment
0
Dimitar Tachev
Telerik team
answered on 06 Feb 2013, 03:55 PM
Hello Michael,

 
If you need to serialize your entities and then deserialize them along with their related object the only way to achieve that is by one of the options that Thomas described in the Forum thread that you have found.

Regarding to your second question, when you detach your entities using the CreateDetachedCopy method with a custom fetch strategy, on the client-side you are getting this part of the object graph that is specified by the fetch plan.

After applying some changes (inserts or updated) over the detached collection - for example if you use the Orders table fetched with their Order Details, add new Order Details to one of the detached orders and then call the AttachCopy method for this Order it will automatically insert the new Order Details because they are related in the detached object graph.

Please bear in mind that you have to build some custom logic about the Deleting of detached objects because the AttachCopy method tracks only the new and updated entities.

Could you please specify what problems do you experience with the uniqueness of the sub-entries after detaching your entities and provide us with some example describing this custom scenario?

I am looking forward to your feedback.

Kind regards,
Dimitar Tachev
the Telerik team
Q3'12 SP1 of OpenAccess ORM packs Multi-Table Entities mapping support. Check it out.
0
Michael
Top achievements
Rank 1
answered on 07 Feb 2013, 07:37 AM
Thanks for your reply.

Our problem is that if we detach the result from the context then the sub objects are not references. The same subobject items exists mutliple times. We get always multiple copys of the sub item an no reference to one object.

If we change a property of a subobjekt-item then the other copys not be affectet.

We have a contacs classe with subitems of nametypes. Every contact can have one or more name entries. The nametypes are categories of names. If a change one nametype (not the value of the nametype) then only the one object will be affectet. Not all objects of the same nametype (example: we change the nametype from "Name1" to "FirstName")

If the result of a query not detached and on serverside then that works - but not if we detach and change on client-side.

I hope you can understand what I need/mean ;-)

An other problem exist if we not detach the result and send to the client - client change the property and send back to the server. On the server we now try

_ContactsContext.GetState(entity) results in 'MaskNoMask {32}' Telerik.OpenAccess.ObjectState
_ContactsContext.AttachCopy(entity) // not a detateched copy!
_ContactsContext.GetState(entity)

then we get the exception

{"Object references between two different object scopes are not allowed. The object 'ContactsEntities.Contact' is already managed by 'ObjectScopeImpl 0x7a' and was tried to be managed again by 'ObjectScopeImpl 0x79 OpenAccessRuntime.EnlistableObjectScope'."}

In your documentation you say that MaskNoMask=Object is not managed by a context. So why can we not attach it?







0
Dimitar Tachev
Telerik team
answered on 11 Feb 2013, 04:36 PM
Hi Michael,

The proper way to pass your data on the client side is the one with the detached object graph.

Generally, after detaching the graph that you need, all of the object references should be exactly the same as the one before the detaching. 

The CreateDetachedCopy method is creating a new copy of the passed collection depending to the passed fetch strategy organized in a new object graph. For example if you detach the Orders tables along with their related Customer, all of the orders that have the same customer will have its same reference after the detaching.

I reviewed you snippets again and I suppose that the reason for your issue with getting different references for the same object could be that you are detaching the object graph part by part as you were doing with the ForEach loop and you are getting a new copy of the same object with each call of the CreateDetachedCopy method.

Could you please confirm that you are using the described approach and detaching an entire graph instead of one object at a time? In other words, detaching related objects with one call as below:

...
detachedList =
context.CreateDetachedCopy(Of List(Of Order))(allOrders, strategy)
...

If this is not your case, let us know if you can send us part of your application so that we investigate what exactly is going wrong? If you can, we will change the thread to a private ticket so that you are able to do so.


All the best,
Dimitar Tachev
the Telerik team
Q3'12 SP1 of OpenAccess ORM packs Multi-Table Entities mapping support. Check it out.
Tags
Data Access Free Edition
Asked by
Michael
Top achievements
Rank 1
Answers by
Dimitar Tachev
Telerik team
Michael
Top achievements
Rank 1
Share this question
or