使用委托的 LINQ 的 LightSwitch 自定义查询不起作用
我在 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
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.