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

CreateDetachedCopy Stream

5 Answers 114 Views
Development (API, general questions)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Alexander
Top achievements
Rank 1
Alexander asked on 04 Jan 2015, 12:08 AM
I have the following code snippet which creates a detached copy of a contact...

EditableItem = Context.CreateDetachedCopy(SelectedItem, con => con.Picture,
                                                                    con => con.MainAddress,     
                                                                    con => con.BillingAddress,
                                                                    con => con.BankAccount,
                                                                    con => con.Organization,
                                                                    con => con.Discount);

Now if I look at my copy all data is there except the picture of the contact which is
a binary. I read the documentation about "Working with Streams" and "Attaching and Detaching"
but I wasn't able to get this up an running. So it would be great if you could help me
or provide me a sample where a binary stream is detached and then attached to the context.

Regards Alex

5 Answers, 1 is accepted

Sort by
0
Accepted
Boyan
Telerik team
answered on 07 Jan 2015, 12:08 PM
Hi Alexander,

As shown in the Working with Streams documentation article, a stream is read at multiple passes retrieving the data at chunks. Reading this stream is done manually and it requires calls to the database meaning that reading it though a detached object would result in InvalidOperationException with the following explanation: Instance is detached, no database operation can be made.

This means that if you would like to detach an object along with its BinaryStream property, the first think you have to do is to read and manually store the binary data before the object is detached. Once you have stored the data you could then detach the object. Both how to read and then re-attach such an object is demonstrated in the Working with Streams documentation article (also linked above).

Alternative approach could be to map this column to byte[] property instead of BinaryStream. This would allow you to include it in the properties to be detached (as you have shown that you do) and detach it. Please note that detaching binary column in such way could lead to performance degradation depending on the size of the retrieved data. Also taking this approach you will lose the ability to easily stream the data.

I hope this is helpful. Do not hesitate to get back to us if you have any more questions or if you need any further assistance.

Regards,
Boyan
Telerik
 
OpenAccess ORM is now Telerik Data Access. For more information on the new names, please, check out the Telerik Product Map.
 
0
Alexander
Top achievements
Rank 1
answered on 12 Jan 2015, 09:49 AM
Hello Boyan,

I changed the mapping of the column to byte[] but still it doesn't work. 
So within the original object the binary property field is not null and the picture is shown  
As soon as I create a detached copy of the object the binary data field is null. All other properties
are loaded correct.

Regards Alex
0
Alexander
Top achievements
Rank 1
answered on 12 Jan 2015, 09:50 AM
I changed the mapping of the column to byte[] but still it doesn't work.
So within the original object the binary property field is not null and the picture is shown  
As soon as I create a detached copy of the object the binary data field is null. All other properties
are loaded correct.
0
Alexander
Top achievements
Rank 1
answered on 12 Jan 2015, 01:08 PM
Found the error. Thanks for your help!
0
Accepted
Boyan
Telerik team
answered on 13 Jan 2015, 11:15 AM
Hello Alexander,

We are glad to hear that you have resolved the issue on your side.

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

Regards,
Boyan
Telerik
 
OpenAccess ORM is now Telerik Data Access. For more information on the new names, please, check out the Telerik Product Map.
 
Tags
Development (API, general questions)
Asked by
Alexander
Top achievements
Rank 1
Answers by
Boyan
Telerik team
Alexander
Top achievements
Rank 1
Share this question
or