none
Linq query output type RRS feed

  • Question

  • Hi all,

    I created a new type called Job

    The job have 3 fields JobId,JobName and JobDate

    Then i have the following function

    Public function GetJob() as List(of Job)  
    Dim MyJob =from J in dc.Jobs select New with {j.JoobId,j.JobName,Job.jobDate} 
    Return MyJob.Tolist 
    End function 
     


    There is an error when using MyJob.toList

    But if i use Return MyJob no error

    then i cannot get the JobId,JobName and JobDate from the function when i use it if it is not a list

    Anyone can help please


    Tuesday, December 30, 2008 5:22 PM

All replies

  • You have given the method a specific return type of List(of Job), yet you are attempting to return List(of ???).  The VB 'New With' expression constructs an anonymous type instance.  This type is not a 'Job', it is some type cooked up by the VB compiler.   Anonymous type values cannot be returned from methods since you cannot say the name of the type in the language.  You can return the list of anonymous types if the method is typed to return Object or plain IEnumerable.
    Wayward LINQ Lacky
    Wednesday, December 31, 2008 8:28 PM
    Moderator