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

Problem with Image and varbinary fields

3 Answers 81 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.
bin
Top achievements
Rank 1
bin asked on 05 Jun 2011, 07:19 AM
Hi sir,
I am using the following code to return two fields from the table TestTable where the field FileContent datatype is Image or VarBinary .

var q = (from tt in objScope.Extent<TestTable>()
                  select new { tt.FileID, tt.FileContent }).ToList();

I got the following exception:-
System.InvalidCastException was unhandled
  Message=Object must implement IConvertible.
  Source=mscorlib
  StackTrace:
       at System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider)
       at Telerik.OpenAccess.Query.NullableConverter`1.Convert(ResultData& data)
       at Telerik.OpenAccess.Query.ArrayConverter`1.Convert(ResultData& data)
       at Telerik.OpenAccess.Query.ObjectConstructor.Convert(ResultData& data)
       at Telerik.OpenAccess.Query.TypedEnumerator`1.ObtainCurrent()
       at Telerik.OpenAccess.Query.TypedEnumerator`1.System.Collections.Generic.IEnumerator<T>.get_Current()
     ... Local paths ...

       at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
       at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ButtonBase.WndProc(Message& m)
       at System.Windows.Forms.Button.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       at  ... Local paths ...
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext, String[] activationCustomData)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssemblyDebugInZone()
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException:

3 Answers, 1 is accepted

Sort by
0
Thomas
Telerik team
answered on 06 Jun 2011, 01:36 PM
Hello bin,

the issue has been fixed already, and the next build will contain the needed changes. As a workaround you can first do an empty projection, and then use the persistent field to perform the projection. 

All the best,
Thomas
the Telerik team
Q1’11 SP1 of Telerik OpenAccess is available for download; also available is the Q2'11 Roadmap for Telerik OpenAccess ORM.
0
bin
Top achievements
Rank 1
answered on 07 Jun 2011, 08:47 AM
Hello Sir,

What do you mean by " you can first do an empty projection, and then use the persistent field to perform the projection " ?
Could you please provide me with a code sample for the empty projection that handles my case.

Thanks
0
Thomas
Telerik team
answered on 07 Jun 2011, 10:51 AM
Hi bin,

I meant

var q = (from tt in objScope.Extent<TestTable>()
         select tt).ToList().Select(xx => new { xx.FileID, xx.FileContent });

So, first perform no projection and thus get real persistent instances back, then use the instances to get the field value. Please make sure that the FileContent is
using the default fetch group too.

All the best,
Thomas
the Telerik team
Q1’11 SP1 of Telerik OpenAccess is available for download; also available is the Q2'11 Roadmap for Telerik OpenAccess ORM.
Tags
Development (API, general questions)
Asked by
bin
Top achievements
Rank 1
Answers by
Thomas
Telerik team
bin
Top achievements
Rank 1
Share this question
or