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

Telerik Openaccess & Linq compiled expression

0 Answers 115 Views
LINQ (LINQ specific 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.
Matteo Ermidoro
Top achievements
Rank 1
Matteo Ermidoro asked on 26 Aug 2009, 11:54 AM
Hello, 

I'm trying to create a "generic" datalayer for my apps. At the moment I'm facing some issue creating a method with this sign :

public T GetSingle<T>(Expression<Func<T, bool>> filter)

I want to use Expression<Func<T, bool>> filter to pass "where" statement to my DAL. 

My code is : 
            var predicate = filter.Compile();
            var scope = ObjectScopeProvider.ObjectScope(ScopeContext.Application);           

            var obj1 = scope.Extent<T>().Where<T>(p => predicate(p));

but with no luck, last row throw this exeption :
System.NotSupportedException was unhandled
  Message="RegionExtent.OfType().Where(p => Invoke(value(OfeX.DataLayer.DatabaseServices.DataBaseServices+<>c__DisplayClass0`1[OfEx.PersistentClasses.Region]).predicate,p))"
  Source="Telerik.OpenAccess.Query"
  StackTrace:
       at Telerik.OpenAccess.Query.QueryContext.CreatedQuery(IQueryable x)
       at Telerik.OpenAccess.Query.QueryContext.CreatedQuery[T](IQueryable`1 x)
       at Telerik.OpenAccess.Query.ObjectScopeQuery`2.CreateQuery[TElement](Expression expressionParam)
       at System.Linq.Queryable.Where[TSource](IQueryable`1 source, Expression`1 predicate)
       at OfeX.DataLayer.DatabaseServices.DataBaseServices.GetSingle[T](Expression`1 filter) in C:\Data\Visual Studio 2005\Projects\OfEx\Ofex\Ofex.DataLayer\DatabaseServices\DataBaseServices.cs:line 74
       at TestDataLayer.Form1.button3_Click(Object sender, EventArgs e) in C:\Data\Visual Studio 2005\Projects\OfEx\Ofex\TestDataLayer\Form1.cs:line 56
       at System.Windows.Forms.Control.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnClick(EventArgs e)
       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.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.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(Int32 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 System.Windows.Forms.Application.Run(Form mainForm)
       at TestDataLayer.Program.Main() in C:\Data\Visual Studio 2005\Projects\OfEx\Ofex\TestDataLayer\Program.cs:line 18
       at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: 


Anyone could help? 

Thanks a lot.

Matteo


-------------------------------------------------------
Solved : 
Seems to be a problem with OpenAccess & "var predicate = filter.Compile();".

I modified the last row in 
var obj1 = scope.Extent<T>().Where<T>(filter);

and now it works.

Thanks 

Matteo
Tags
LINQ (LINQ specific questions)
Asked by
Matteo Ermidoro
Top achievements
Rank 1
Share this question
or