如何在代码隐藏中使用Lightswitch linq进行联合? [英] How to do union in Lightswitch linq in code-behind?
问题描述
所以,我创建了一个查询,并且我处于Preprocess事件中,我想要联合,但它不起作用。
So, I created a query and I'm in Preprocess event where I would like to do union, but it doesn't work.
联合签名是IQueryable< T> .Union(IEnumerable< T> second),但我不知道如何在Lightswitch中获得IEnumerable。每个查询都是IQueryable,无法转换为IEnumerable。
Signature of union is IQueryable<T>.Union(IEnumerable<T> second), but I have no idea how to get IEnumerable in Lightswitch. Each query is IQueryable and can not be casted to IEnumerable.
我正在尝试这样做:
partial void MyQuery_PreprocessQuery(ref IQueryable<MyType> query)
{
var test = from row in Table
where row.Id == 0
select row;
query = (from row in query
select row.MyType).Union(test);
}
推荐答案
嗨马里奥,
IQueryable已经是IEnumerable,所以不需要在那里进行转换。
An IQueryable is already IEnumerable, so no casting is necessary there.
当你说"它不起作用"时,你能更具体一点吗?
When you say "it doesn't work", can you be more specific?
你无法改变"形状"。在PreProcess中,您必须返回相同"类型"的记录。正如PreProcess方法中定义的那样(它将是查询所基于的实体),但如果这是您的问题,我无法看到您显示的内容,或者
没有。
You can't change the "shape" of the data in PreProcess, you have to return records of the same "type" as defined in the PreProcess method (which will be the entity the query is based on), but I can't see from what you've shown if this is your problem or not.
您是否可以提供整个PreProcess方法,以及错误等, &那么你可能很容易给出答案。
Could you maybe provide the whole of your PreProcess method, plus the error etc, & then it might be easy to give you an answer.
Yann
这篇关于如何在代码隐藏中使用Lightswitch linq进行联合?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!