2

I have problems in designing an extended query in the ...PreprocessQuery() Method of a LightSwitch query.

1st of all, I tell you in a simplified way, what works:

partial void NeedHelp_PreprocessQuery(bool Admin, ref IQueryable<Device> query)
{
  // Some code...
  query = query.Where<Device>(d => d.IsAvailable());
}

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<Device> query)
{
  // Some code...
  Func<Device, bool, bool> LogicDelegate = new Func<Device, bool, bool>(this.Logic);
  query = query.Where<Device>(d => LogicDelegate(d, Admin));
}

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?

César
  • 9,939
  • 6
  • 53
  • 74
Satria
  • 315
  • 2
  • 9

1 Answers1

0

There is no support for inline code in linq2sql - its just imagination ;).

When you do something as 'item.Trim()' behind the scenes this will be translate to the SQL command LTRIM(RTRIM(item))

You may check Views in MSSQL.

Yacov
  • 1,060
  • 14
  • 27
  • Thanks for the answer. I solved this now with a workaround, in which I added a new field into the table, where the date ticks are stored as a long int. This is managed in parallel to the original DateTime field... Not very nice, but works good and easily. – Satria Nov 29 '11 at 09:36