gpt4 book ai didi

c# - 使用 LINQ 将两个不同类型的 IQueryable 变量连接在一起

转载 作者:太空狗 更新时间:2023-10-29 23:52:17 25 4
gpt4 key购买 nike

列名称和类型相同,但它来自两个不同的实体。这是一个简化的示例:

--Query View
var v_res = from s in db.V_CMUCUSTOMER
select s;

--Values from table less values from view
var res = from s in db.CMUCUSTOMERs
where !(from v in v_res
select v.ID).Contains(s.ID)
select s;

--join table and view values into one variable
var res_v_res = (from c in res
select c).Union(from v in v_res
select v);

但是我收到以下错误:

实例参数:无法从“System.Linq.IQueryable”转换为 System.Linq.ParallelQuery

最佳答案

如果您指定一个新的匿名类型并为两者使用 ToList(),那么您应该能够按如下方式联合它们:

var v_res = (from s in db.V_CMUCUSTOMER
select new { custName = s.customer_name custAddress = s.address}).ToList();

--Values from table less values from view
var res = (from s in db.CMUCUSTOMERs
where !(from v in v_res
select v.ID).Contains(s.ID)
select new { custName = s.customer_name custAddress = s.address }).ToList();

--join table and view values into one variable
var res_v_res = v_res.Union(res);

如果有几十列,这可能会很麻烦,但应该仍然有效。

关于c# - 使用 LINQ 将两个不同类型的 IQueryable 变量连接在一起,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11190152/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com