It does not seem to be a LINQ problem itself, but ... there is no LightSwitch Forum ;)
1st of all, I tell you in a simplified way, what works:
partial void NeedHelp_PreprocessQuery(bool Admin, ref IQueryable query)
{
// Some code...
query = query.Where(d => d.IsAvailable());
}
{
// Some code...
query = query.Where
}
The query does not show any compile error and does what it should do.
Now, when I try to put the logic into a method and use its delegate in the query, there's no compile error either, but I get an exception. Here is the code:
private bool Logic(Device TheDevice, bool Admin)
{
return Admin ? true : TheDevice.IsAvailable();
}
partial void NeedHelp_PreprocessQuery(bool Admin, ref IQueryable query)
{
// Some code...
Func LogicDelegate = new Func(this.Logic);
query = query.Where(d => LogicDelegate(d, Admin));
}
{
return Admin ? true : TheDevice.IsAvailable();
}
partial void NeedHelp_PreprocessQuery(bool Admin, ref IQueryable
{
// Some code...
Func
query = query.Where
}
The Exception is in German, I try to translate the essential:
The expression is not supported. Expression: Invoke(value(LightSwitchApplication.ApplicationDataService+<>c_DisplayClass4).LogicDelegate, d, value(LightSwitchApplication.ApplicationDataService+<>c_DisplayClass4).Admin) Message of inner exception: The type "ApplicationData.Implementation.Device" cannot be used for a parameter of type "LightSwitchApplication.Device".
Since I am only using "Device", I do not understand this confusion between ApplicationData.Implementation.Device and LightSwitchApplication.Device! What am I doing wrong? Or is this kind of call simply not possible in LightSwitch?
Satria SudewoPosted Nov 22, 2011, 1:01 PM
And I happen to already have posted the question in the very forum you have linked, thanks ;)
VulpesPosted Nov 22, 2011, 12:20 PM
Satria SudewoPosted Nov 22, 2011, 11:10 AM
Thanks for your quick reply.
In the IDE, so during development, the namespace/class "ApplicationData.Implementation.Device" is unknown / not available.
And using "LightSwitchApplication.Device" explicitly doesn't help, which I had already tried of course.
The definition of the class "Device" is not done by the developer, but by LightSwitch somewhere in the code, when you create the table "Device" in the Data designer and usually you use "Device" in every relevant module. From what is exposed to the developer, this all is very confusing, because for you, you only created ONE Device entity...
There's also the method ".cast
VulpesPosted Nov 22, 2011, 11:00 AM