简体   繁体   English

带参数的lightswitch查询

[英]lightswitch query with parameter

I have a list where I select an item. 我有一个清单,供我选择项目。 Based on some field of this item i want to filter a choice list in another Control. 基于此项的某些字段,我想过滤另一个控件中的选择列表。

Somehing like that: 像这样的东西:

Select * from choiceItems Where choiceItem.ID = (Select ID from anotherTable where anotherTable.ID = selectedItem.ID)

the problem is that it is possible that there are more ID returns. 问题是可能有更多的ID返回。 Maybe I want all the choiceItems with the ID = {3,2,1} etc. 也许我想要所有ID = {3,2,1}等的choiceItems。

I cant preprocess the query on the server since my parameter is depending on the selected item in the list. 我无法在服务器上预处理查询,因为我的参数取决于列表中的所选项目。 If i try to filter the result in the query editor i can only specify on parameter which can be only a single value (fe ID=2). 如果我尝试在查询编辑器中过滤结果,则只能在只能为单个值(fe ID = 2)的参数上指定。

How do i do that in silverlight? 如何在Silverlight中做到这一点?

Also, another unrelated small problem: Is it possible to show the waiting cursor while loading a custom control in lightswitch (right now it just displays a grey area until the data and controls are loaded). 另外,还有一个不相关的小问题:是否可以在将自定义控件加载到lightswitch中时显示等待的光标(现在,它仅显示灰色区域,直到加载数据和控件为止)。

Select * from choiceItems Where choiceItem.ID = (Select ID from anotherTable where anotherTable.ID = selectedItem.ID) 从choiceItems中选择*,其中choiceItem.ID =(从anotherTable中选择ID,其中anotherTable.ID = selectedItem.ID)

This is a many to many secenario, you need to make a WCF RIA Service with query parameter, a lot of work just for filtering. 这是许多步骤,您需要制作带有查询参数的WCF RIA服务,许多工作仅用于过滤。 The alternative is to make those tables related. 另一种方法是使那些表相关。

You should be able to preprocess the query even if the parameter for the query is selected from a list. 即使从列表中选择了查询参数,您也应该能够对其进行预处理。 You can then use LINQ to return a subset of your choiceItems or, based on the selected parameter, skip the LINQ which would return all of the choiceItems . 然后,您可以使用LINQ返回您的choiceItems的子集,或者基于选定的参数,跳过将返回所有choiceItems的LINQ。

I give a detailed example of doing this in my answer to the SO question: 我在回答SO问题时给出了执行此操作的详细示例:

Is there a way to create a search screen in Lightswitch based on a dropdown 有没有一种方法可以基于下拉列表在Lightswitch中创建搜索屏幕

Don't have the exact syntax, but should be something like this: 没有确切的语法,但是应该是这样的:

first get the ID using LINQ 首先使用LINQ获得ID

var FilterOnThisId=this.Query1.Where(x=>x.ID==selectedItem.ID).FirstOrDefault();

then query the colleciton you want 然后查询您想要的大学

var filtedItems=this.Query2.Where(x=>x.ID==FilterOnThisId);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM