Print Page | Close Window

Question on querying unions

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=4204
Printed Date: 23-May-2024 at 3:34pm


Topic: Question on querying unions
Posted By: BillG
Subject: Question on querying unions
Date Posted: 01-Jul-2013 at 12:18am
I have two tables in my database. One table holds payments and the other holds charges. I have a view that unions the two tables together. When i run a query in Enterprise Manager for a specific she has a total of 292 rows. When i try to retrieve the records for her using Linq only 26 records are returned. Its like the query stops returning records before the union is finishing joining all the rows. Any suggestions? BTW this is DevForce 2010. I cannot use .net 4.5 as i have too many clients still using XP at this point.
 
Here is my query
 
     public void GetMemberTransactionsAsync(string socSecNo, Action<IEnumerable<MemberTransaction>> onSuccess,
                               Action<Exception> onFail)
        {
            var query = Manager.MemberTransactions
                      .Where(m => m.socsecno == socSecNo)
                      .OrderBy(m => m.TranDate)
                   .ExecuteAsync(
                       op =>
                       {
                           if (op.CompletedSuccessfully)
                           {
                               if (onSuccess != null)
                                   onSuccess(op.Results);
                           }
                           else
                           {
                               if (onFail != null)
                               {
                                   op.MarkErrorAsHandled();
                                   onFail(op.Error);
                               }
                           }
                       }
                );
        }
 
Here is my union and view
SELECT     socsecno, datedeb AS trandate, round(duesamount, 2) AS tranamount, 'D' AS trancode, isnull(duescatdesc, '***') AS trantype, 0 AS receipt, '' AS paidthru, isnull(note, ' ') 
                      AS remark, duesowed.duescatcd
FROM         duesowed LEFT JOIN
                      duescateg ON duesowed.duescatcd = duescateg.duescatcd
UNION ALL
SELECT     socsecno, batchdate AS trandate, round((duesamount * - 1), 2) AS tranamount, 'P' AS trancode, isnull(paytypedesc, '***') AS trantype, receiptno AS receipt, paidthru,
                      isnull(checkno, ' ') AS remark, duescatcd
FROM         memdues LEFT JOIN
                      paytypes ON memdues.paytype = paytypes.paytype
 
Am I going to have to read both tables and merge them myself in code or can this be fixed?
 



Replies:
Posted By: BillG
Date Posted: 01-Jul-2013 at 4:30am
Further research reveals the following. If i change the async call to a sync call it produces exactly the same result. So the problem appears to be that the query quits before all the rows come back. It must have to do with how SQL Server does unions. Has anyone had any luck querying unions?



Posted By: kimj
Date Posted: 01-Jul-2013 at 8:01am
Check the EntityKey for the MemberTransaction entity.   Each row returned from your view needs to have a unique key.



Print Page | Close Window