Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Cannot retrive a single record from Anonymous Type

Cannot retrive a single record from Anonymous Type

Scheduled Pinned Locked Moved ASP.NET
linqcsharpdatabasehelpquestion
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    awedaonline
    wrote on last edited by
    #1

    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.MailContent

            If 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?

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups