无法合并 EF 中的两个函数结果

Failed to union two function results in EF

我试图合并两个 SQL Table 函数调用的结果集,但我一直收到此错误 "The 'Distinct' operation cannot be applied to the collection ResultType of the specified argument.Parameter name: argument"

到目前为止,我已经尝试了所有方法,包括 "Make a primary key in function result table"、"Adding a [key] attribute to result in entityframework model of function result",但似乎没有任何效果。

这是我的 Linq 语法,如有任何帮助或建议,我将不胜感激。

var dataPlan = Context.fn_GetPlans(3, 1, userId);
var dataPlan1 = Context.fn_GetPlans(3, 2, userId);

var ddataPlan = dataPlan.Union(dataPlan1);

好的,到目前为止还没有答案对我有用,因为我想要一种方法将结果保存在 IQueryable 中,

所以接受这个事实,我 return 进入我的数据库并处理数据库函数 return 多个函数本身的结果,并在数据库端合并它们。

这对我有用,我希望遇到这个问题的其他人在工作中考虑这个解决方案。

我有同样的错误并通过创建我自己的 class 来解决它,它具有与函数结果类型相同的属性,并将查询投影到那个 class,例如:

var dataPlan = Context.fn_GetPlans(3, 1, userId)
    .Select(p => new MyClass
                 {
                     PropertyA = p.PropertyA,
                     PropertyB = p.PropertyB,
                     // ... etc...
                 });

我不明白为什么原来的 class 不起作用,但新查询可以被 Uninon 处理得很好。