none
anonymous type RRS feed

  • Question

  • Public Function GetProduct(ByVal mxID As IntegerAs List(Of dtProduct) Implements IService1.GetProduct   
      
            Dim dc As New DataContext()   
            Dim results = From c In dc.dtProducts _   
                Where c.ProductID < mxID _   
                 Select new with{c.ProductName,c.ProductPrice}  
      
            Return results.ToList   
        End Function  

    When i use this code it give a squiggly line under .ToList but if i change  the linq to


    Public Function GetProduct(ByVal mxID As IntegerAs List(Of dtProduct) Implements IService1.GetProduct   
      
            Dim dc As New DataContext()   
            Dim results = From c In dc.dtProducts _   
                Where c.ProductID < mxID _   
                 Select c   
      
            Return results.ToList   
        End Function  
    no errors

    What should I dim the anonymous type as if the output is not a list

    Saturday, December 27, 2008 12:24 AM

All replies

  • You can not return an anonymous type from a function - this is a limitation of anonymous types that is part of the language not specifically LINQ to SQL.

    What you need to do is declare a new type and project into that and mark the function as returning a List of the new type.

    [)amien
    Sunday, December 28, 2008 3:59 AM
    Moderator
  • Thank you for your reply

    But can you explain how to create the new type with may be ProductName , ProductPrice

    And how can i use that new type in my function

     

    Sunday, December 28, 2008 5:17 PM