Cannot retrive a single record from Anonymous Type
-
I am getting error when I tried retriving a single row from my LINQ query. This is my code:
Dim query = From mm In dataContext.Mail_Message
Group Join mmr In dataContext.Mail_MessageRecipient On mm.MailMessageId Equals mmr.MailMessageId Into mmrm = Group From mrm In mmrm.DefaultIfEmpty
Group Join u In dataContext.Application_User On mm.SenderId Equals u.UserId Into us = Group From ums In us.DefaultIfEmpty
Group Join sr In dataContext.Personnel_StaffRecord On ums.StaffRecordId Equals sr.StaffRecordId Into srm = Group From smrm In srm.DefaultIfEmpty
Group Join ma In dataContext.Mail_MessageAttachment On mm.MailMessageId Equals ma.MailMessageId Into mam = Group From mamm In mam.DefaultIfEmpty
Where mm.MailMessageId = messageId
Select mrm.MailMessageRecipientId, smrm.Surname, smrm.Firstname, smrm.Othername, mm.Date, mm.Subject, mm.MailContentIf query IsNot Nothing Then Dim row = query(1) With result .MailMessageId = row.MailMessageRecipientId .Sender = CStr(IIf(row.Surname Is Nothing, "BISM Limited", String.Format("{0} {1} {2}", row.Surname, row.Firstname, row.Othername))) .Subject = row.Subject .Body = row.MailContent .Dates = row.Date .RecipientNames = GetMailRecipients(messageId) .Attachments = GetMailAttachments(messageId) End With ReadMessage(row.MailMessageRecipientId) End If
This is the error I get:
LINQ to Entities does not recognize the method 'VB$AnonymousType_48`7[System.Int64,System.String,System.String,System.String,System.DateTime,System.String,System.String] ElementAtOrDefault[VB$AnonymousType_48`7](System.Linq.IQueryable`1[VB$AnonymousType_48`7[System.Int64,System.String,System.String,System.String,System.DateTime,System.String,System.String]], Int32)' method, and this method cannot be translated into a store expression.
What am I getting wrong here?