实体框架查询。计数不会产生选择计数(*)

时间:2019-11-18 14:25:45

标签: sql entity-framework select count

我有用Entity Framework编写的查询:

var query2 = from m in _attadoContext.Mails
             join orel in _attadoContext.ObjectRelations on 
                       new { m1 = (Int64)m.MailId } equals new { m1 = (Int64)orel.FirstObjectId }
             join orelTask in _attadoContext.ObjectRelations on 
                           new { m10 = (Int64)m.MailId, m20 = (Int16)(int)EntityType.Mail, m30 = (Int16)(int)EntityType.Task } equals new
                             {
                                 m10 = orelTask.FirstObjectId,
                                 m20 = (Int16)orelTask.FirstObjectType,
                                 m30 = (Int16)orelTask.SecondObjectType
                             } 
             // into tasks
             //  where orel.SecondObjectId == contactId && orel.FirstObjectType == (int)EntityType.Mail && orel.SecondObjectType == (int)EntityType.Contact
             //  where m.MailStub.GetValueOrDefault() == false //omit stubs
             select new AttadoMailViewModel()
                        {
                            MailId = m.MailId,
                            Number = m.Number,
                            UserId = m.UserId,
                            MailType = m.MailType,
                            RegisteredDate = m.RegisteredDate,
                            MailSentReceivedDate = m.MailSentReceivedDate,
                            MailOriginalId = m.MailOriginalId,
                            MailSubject = m.MailSubject,
                            MailFrom = m.MailFrom,
                            MailTo = m.MailTo,
                            MailBody = m.MailBody
                       };

当我调用query.Count()时,它会产生select count(*),但是当我添加into tasks或where子句时,查询将更改为选择MailId,Number ...

如何进行完整查询以生成select count(*)

0 个答案:

没有答案