本文介绍了linq union中的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 嗨朋友, 我有3张桌子。 所有桌子都有AddressID字段。 我想使用linq union查询获取相同的字段。 我尝试了下面的查询 我尝试了什么: Hi Friends,I have 3 tables.All table having AddressID field. I want to take the same field using linq union query.I tried the below queryWhat I have tried:var a = from data in db.m_employee join u in db.m_user on data.EmployeeID equals u.EmployeeID where data.AddressID == AddressID && u.IsActive == true select new { TableName = "User", StockLocationID = data.AddressID }; var b = from x in db.m_productrawstock where x.AddressID == AddressID && x.StockQuantity > 0 select new { TableName = "Transaction", StockLocationID = x.AddressID}; var q = a.Union(b); 它显示通过使用默认的相等比较器生成两个序列的集合联合。 它抛出错误:System.ArgumentNullException。 如何在linq union中使用相同的AddressID字段?It shows "Produces the set union of two sequences by using the default equality comparer."It throws error : System.ArgumentNullException.How can I use the same AddressID Field in linq union?推荐答案 您不能使用联盟这样! 你必须提供 IEqualityComparer 才能使用Union。 查看:可数.Union(TSource)方法(IEnumerable(TSource),IEnumerable(TSource))(System.Linq) [ ^ ] You can't use Union this way!You have to provide IEqualityComparer to be able to use Union.Check this: Enumerable.Union(TSource) Method (IEnumerable(TSource), IEnumerable(TSource)) (System.Linq)[^] 这篇关于linq union中的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-26 20:07