使用委托的 LINQ 的 LightSwitch 自定义查询不起作用

发布于 2024-12-17 22:09:43 字数 1429 浏览 4 评论 0原文

我在 LightSwitch 查询的 ...PreprocessQuery() 方法中设计扩展查询时遇到问题。

首先,我以一种简化的方式告诉您,什么是有效的:

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

查询不会显示任何编译错误并执行其应该执行的操作。


现在,当我尝试将逻辑放入方法并在查询中使用其委托时,也没有编译错误,但出现异常。这是代码:

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 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".

由于我只使用 Device,我不明白 ApplicationData.Implementation.Device 之间的这种混淆> 和 LightSwitchApplication.Device!我做错了什么? 或者这种调用在 LightSwitch 中根本不可能实现?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

掌心的温暖 2024-12-24 22:09:43

linq2sql 中不支持内联代码 - 这只是想象;)。

当您在幕后执行“item.Trim()”操作时,这将被转换为 SQL 命令 LTRIM(RTRIM(item))

您可以检查 MSSQL 中的视图。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文