kkumar
kkumar

Reputation: 355

LINQ query does not return any results when using with where condition

 var iquery = (from m in dc.m_MAILBOXes 
            join o in dc.o_ORGANIZATIONs on m.m_o_ID equals o.o_ID
            join h in dc.h_HOSTED_EXCHANGE_ACCOUNTs on  o.o_ID  equals h.h_o_ID
            join my in dc.my_MAILBOX_SUMMARies on m.m_ID equals my.my_m_ID
            orderby my.my_START_DATE descending
          select new { MailboxName = m.m_NAME, OrgName = o.o_NAME, MailboxStatus = m.m_STATUS,
          LatestEndDate = my.my_END_DATE, AccountStatus = h.h_STATUS }).Where(r => r.MailboxName == "[email protected]")); 

This is the query I am using along with where condition and does not return any results. I am exactly not sure where i am going wrong. When I remove where condition query returns results along with the entry where mailboxname is equal to "[email protected]".

var result = iquery .Select(var => new MailBoxReconEntry
                                  {
                                      AccountStatus = var.AccountStatus, LatestEndDate = var.LatestEndDate, 
                                      MailboxStatus = var.MailboxStatus,
                                      OrgName = var.OrgName
                                  }).ToList();

Upvotes: 0

Views: 764

Answers (1)

James Smithy Cleave
James Smithy Cleave

Reputation: 131

Shouldn't the where statement go in the main LINQ request,

The LINQ Request is converted to SQL so the where statement should be part of the LINQ Query not after

So

 var iquery = (from m in dc.m_MAILBOXes 
        join o in dc.o_ORGANIZATIONs on m.m_o_ID equals o.o_ID
        join h in dc.h_HOSTED_EXCHANGE_ACCOUNTs on  o.o_ID  equals h.h_o_ID
        join my in dc.my_MAILBOX_SUMMARies on m.m_ID equals my.my_m_ID
        where m.MailboxName == "[email protected]"
        orderby my.my_START_DATE descending

Bit rough but should give you the idea?

Upvotes: 2

Related Questions