tag:blogger.com,1999:blog-13459850.post2487804395670441576..comments2023-10-15T08:07:08.589+00:00Comments on Forwards: Linq to SQL and UNION - "All queries combined using a UNION, INTERSECT or EXCEPT operator must have an equal number of expressions in their target lists."Unknownnoreply@blogger.comBlogger7125tag:blogger.com,1999:blog-13459850.post-23725802789350900302010-08-23T14:55:58.774+00:002010-08-23T14:55:58.774+00:00Thanks, using the let keyword worked perfectly.Thanks, using the let keyword worked perfectly.Rosana de Oliveirahttps://www.blogger.com/profile/06569993236084681807noreply@blogger.comtag:blogger.com,1999:blog-13459850.post-45070149847148977312010-05-21T09:27:32.636+00:002010-05-21T09:27:32.636+00:00After struggling from 10 days, converting to ToLis...After struggling from 10 days, converting to ToList() solved my problem. Thanks.Ravihttps://www.blogger.com/profile/13580173158454802484noreply@blogger.comtag:blogger.com,1999:blog-13459850.post-39762183059725958312010-03-03T18:12:20.077+00:002010-03-03T18:12:20.077+00:00I like Jeff's solution. It's hacky, but in...I like Jeff's solution. It's hacky, but in the best possible way to deal with a Microsoft bug. Thanks man.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-13459850.post-84707618742565759812010-02-08T15:15:45.264+00:002010-02-08T15:15:45.264+00:00@Mike,
While this does fix it, it completely dest...@Mike,<br /><br />While this does fix it, it completely destroys any advantages you get from using the IEnumerable (or IQueryable) returned by Linq2SQL. Creating an in-memory list with large data is pretty bad performance wise.<br /><br />It does work, just not well. I would consider this a bug in Linq2SQL.Brandon Perryhttps://www.blogger.com/profile/04227634714412263524noreply@blogger.comtag:blogger.com,1999:blog-13459850.post-80127547411184610752009-11-24T21:49:13.475+00:002009-11-24T21:49:13.475+00:00I had this problem today and solved it by converti...I had this problem today and solved it by converting the queries to lists first using the ToList function then doing a Union. Hope that helps.Unknownhttps://www.blogger.com/profile/02372160141330861792noreply@blogger.comtag:blogger.com,1999:blog-13459850.post-14326118072410301612009-07-23T11:45:23.412+00:002009-07-23T11:45:23.412+00:00I've been struggling with the same problem and...I've been struggling with the same problem and I'm glad to say that I've found a temporary workaround. The workaround is easy but feels like quite a hack.<br /><br />Basically I use the let keyword to set up some temporary range variables to hold my temporary values.<br /><br />In your case I believe it would look something like this.<br /><br />from ...<br /><br />let d1 = -1<br />let d2 = string.Empty<br />let d3 = string.Empty<br />let d4 = -1<br /> <br />select new FeedItem()<br />{<br />...<br /> CommentingUserId = d1,<br /> CommentingUserName = d2,<br /> CommentText = d3,<br /> CommentId = d4,<br />...<br />}<br /><br />The SQL this produces is also more messy than it should be however it seems to perform just fine. For me this one of the top items I hope they address in Linq to SQL for .NET Framework 4.0.Jeffhttps://www.blogger.com/profile/12132574804779166613noreply@blogger.comtag:blogger.com,1999:blog-13459850.post-71507183104621892122009-02-26T12:29:00.000+00:002009-02-26T12:29:00.000+00:00I've got a similar problem that I've not m...I've got a similar problem that I've not managed to solve as yet. My query is:-<BR/><BR/>var allActiveOrders = from o in db.Orders where o.Active select o;<BR/><BR/>Further down I setup 2 queries that get different parts of the orders table and then UNION both results. This works fine. But if I also want to check that the customer is active and I change it to:<BR/><BR/>var allActiveOrders = from o in db.Orders where o.Active && o.Customer.Active select o;<BR/><BR/>the UNION fails because the SQL generated for the first half of the UNION has Customer.ScreenName column appended to it, wheras the second half doesn't. Any ideas would be appreciated! Ta.Rob Brownhttps://www.blogger.com/profile/08431432081738240612noreply@blogger.com