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. General Programming
  3. LINQ
  4. Return a List using LINQ

Return a List using LINQ

Scheduled Pinned Locked Moved LINQ
questioncsharpdatabaselinqhelp
7 Posts 3 Posters 15 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.
  • I Offline
    I Offline
    Illegal Operation
    wrote on last edited by
    #1

    Hi! I need some help. This is very trivial but I seem to be struggling. How do I return a List from the below mentioned code?

    private List GetOrderHeaders()
    {
    var TestVar = from OH in db.SF_GetLatestOrderEntry()
    select OH;
    }

    Illegal Operation

    A D 3 Replies Last reply
    0
    • I Illegal Operation

      Hi! I need some help. This is very trivial but I seem to be struggling. How do I return a List from the below mentioned code?

      private List GetOrderHeaders()
      {
      var TestVar = from OH in db.SF_GetLatestOrderEntry()
      select OH;
      }

      Illegal Operation

      A Offline
      A Offline
      Arun Jacob
      wrote on last edited by
      #2

      Have you tried, return TestVar.toList()

      Arun Jacob http://codepronet.blogspot.com/

      I 1 Reply Last reply
      0
      • A Arun Jacob

        Have you tried, return TestVar.toList()

        Arun Jacob http://codepronet.blogspot.com/

        I Offline
        I Offline
        Illegal Operation
        wrote on last edited by
        #3

        Yes and I get this error Cannot implicitly convert type'System.Collections.Generic.List<WindowsFormsApplication1.SF_SelectLatestOrderEntryResult>' to 'System.Collections.Generic.List

        Illegal Operation

        1 Reply Last reply
        0
        • I Illegal Operation

          Hi! I need some help. This is very trivial but I seem to be struggling. How do I return a List from the below mentioned code?

          private List GetOrderHeaders()
          {
          var TestVar = from OH in db.SF_GetLatestOrderEntry()
          select OH;
          }

          Illegal Operation

          A Offline
          A Offline
          Arun Jacob
          wrote on last edited by
          #4

          Modify method as,

          private List<WindowsFormsApplication1.SF_SelectLatestOrderEntryResult> GetOrderHeaders()
          {
          var TestVar = from OH in db.SF_GetLatestOrderEntry()
          select OH;
          return TestVar.toList();
          }

          or simply,

          private List<WindowsFormsApplication1.SF_SelectLatestOrderEntryResult> GetOrderHeaders()
          {
          return db.SF_GetLatestOrderEntry().toList();
          }

          Arun Jacob http://codepronet.blogspot.com/

          I 1 Reply Last reply
          0
          • A Arun Jacob

            Modify method as,

            private List<WindowsFormsApplication1.SF_SelectLatestOrderEntryResult> GetOrderHeaders()
            {
            var TestVar = from OH in db.SF_GetLatestOrderEntry()
            select OH;
            return TestVar.toList();
            }

            or simply,

            private List<WindowsFormsApplication1.SF_SelectLatestOrderEntryResult> GetOrderHeaders()
            {
            return db.SF_GetLatestOrderEntry().toList();
            }

            Arun Jacob http://codepronet.blogspot.com/

            I Offline
            I Offline
            Illegal Operation
            wrote on last edited by
            #5

            Thank you! That worked. Another quick question? I have a LINQ query returning results

                    var OrderHeader = (from OrderHeaders in db.OEORDHs
                                       where OrderHeaders.COMPLETE != 5 && OrderHeaders.COMPLETE != 4 && OrderHeaders.COMPLETE != 3
                                       orderby OrderHeaders.ORDUNIQ descending
                                       select OrderHeaders);
            

            How can I assign the results to properties? I have created a property named pCustomer and modified the code but that does not work.

                    var OrderHeader = (from OrderHeaders in db.OEORDHs
                                       where OrderHeaders.COMPLETE != 5 && OrderHeaders.COMPLETE != 4 && OrderHeaders.COMPLETE != 3
                                       orderby OrderHeaders.ORDUNIQ descending
                                       select new
            

            {
            pCustomer = OrderHeaders.Customer
            });

            Illegal Operation

            A 1 Reply Last reply
            0
            • I Illegal Operation

              Hi! I need some help. This is very trivial but I seem to be struggling. How do I return a List from the below mentioned code?

              private List GetOrderHeaders()
              {
              var TestVar = from OH in db.SF_GetLatestOrderEntry()
              select OH;
              }

              Illegal Operation

              D Offline
              D Offline
              dan sh
              wrote on last edited by
              #6

              Try this:

              var TestVar = (from OH in db.SF_GetLatestOrderEntry()
              select OH).ToList();

              1 Reply Last reply
              0
              • I Illegal Operation

                Thank you! That worked. Another quick question? I have a LINQ query returning results

                        var OrderHeader = (from OrderHeaders in db.OEORDHs
                                           where OrderHeaders.COMPLETE != 5 && OrderHeaders.COMPLETE != 4 && OrderHeaders.COMPLETE != 3
                                           orderby OrderHeaders.ORDUNIQ descending
                                           select OrderHeaders);
                

                How can I assign the results to properties? I have created a property named pCustomer and modified the code but that does not work.

                        var OrderHeader = (from OrderHeaders in db.OEORDHs
                                           where OrderHeaders.COMPLETE != 5 && OrderHeaders.COMPLETE != 4 && OrderHeaders.COMPLETE != 3
                                           orderby OrderHeaders.ORDUNIQ descending
                                           select new
                

                {
                pCustomer = OrderHeaders.Customer
                });

                Illegal Operation

                A Offline
                A Offline
                Arun Jacob
                wrote on last edited by
                #7

                Instead of assigning object, assign properties,

                var OrderHeader = (from OrderHeaders in db.OEORDHs
                where OrderHeaders.COMPLETE != 5 && OrderHeaders.COMPLETE != 4 && OrderHeaders.COMPLETE != 3
                orderby OrderHeaders.ORDUNIQ descending
                select new pCustomer()
                {
                propertyname1 = OrderHeaders.Customer.propertyname1,
                propertyname2 = OrderHeaders.Customer.propertyname2
                });

                Arun Jacob http://codepronet.blogspot.com/

                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