基于子项过滤父(标题)记录 [英] Filtering Parent (Header) Records Based on Child
问题描述
我有两个桌子.
- 一个存储订单标头信息(例如订单号,送货地址,客户,销售人员,电话号码)的人
- 另一个存储有诸如股票代码,订购数量之类的详细信息
它们以一对多关系连接在一起,以便订单抬头到订单详细信息.我想允许用户根据子项进行搜索(即查找其中包含产品x的所有订单).我看了看长度,可以找到相反的方向(过滤子 基于大师),但对此却没有运气.
They are joined on a one to many relationship for order header to order details. I want to allow the user to search based on the child (i.e. find all orders that have product x in them). I have looked at length and can find the opposite (filtering child based on master) but no luck on this one.
我确定这必须可用吗?
谢谢
詹姆斯
推荐答案
您需要创建一个自定义查询,并在预处理事件中添加代码以进行过滤.
You need to create a custom query and add code in the pre-process event to do the filtering.
下面是一个示例,其中包含一些可选参数,可按部分产品名称和产品代码进行过滤.
Here is an example with a couple of optional parameters to filter by partial product name and product code.
OrderHeaders<-=> OrderLines< =->产品
OrderHeaders <-=> OrderLines <=-> Products
在这种情况下,示例事件代码为:
And the sample event code in this case is:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.LightSwitch;
using Microsoft.LightSwitch.Security.Server;
namespace LightSwitchApplication
{
public partial class ApplicationDataService
{
partial void OrdersByProduct_PreprocessQuery(string ProductName, string ProductCode, ref IQueryable<OrderHeader> query)
{
if (!String.IsNullOrEmpty(ProductName))
{
if (String.IsNullOrEmpty(ProductCode))
{
query = from order in query where order.OrderLines.Any(ol => ol.Product.Name.Contains(ProductName)) select order;
}
else
{
query = from order in query where order.OrderLines.Any(ol => ol.Product.Name.Contains(ProductName) && ol.Product.ProductCode.Contains(ProductCode)) select order;
}
}
else if (!String.IsNullOrEmpty(ProductCode))
{
query = from order in query where order.OrderLines.Any(ol => ol.Product.ProductCode.Contains(ProductCode)) select order;
}
}
}
}
如果是VB,则使用代码转换器将C#转换为VB.
If it is VB then use a code converter to translate C# to VB.
欢呼
戴夫
这篇关于基于子项过滤父(标题)记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!