我有用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(*)
?