简体   繁体   中英

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 == "test@hetest.com")); 

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 "test@hetest.com".

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

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 == "test@hetest.com"
        orderby my.my_START_DATE descending

Bit rough but should give you the idea?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM