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. C#
  4. Lists C#

Lists C#

Scheduled Pinned Locked Moved C#
csharphelplinqsalestutorial
8 Posts 3 Posters 2 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.
  • R Offline
    R Offline
    Rui Couto
    wrote on last edited by
    #1

    Hi
    I'm trying to create a "FinalDocument" list from another list "OriginDocument"
    The problem is that the "FinalDocument" does not have the correct Client Code.
    So I want to get this Client Code from a third List "clients", for that I use the "TaxClienteID" field

    It would be something like this:

    List finalDocument = originDocument.Select(p => new FinalDocument()
    {
    documentcode = p.documentcode,
    date = p.date,
    ...
    codcliente = clients.codcliente where (TaxClienteID = clients.TaxClienteID)
    })

    I'm not getting it, the best I could get was with this:

    List finalDocument = originDocument.Select(p => new FinalDocument()
    {
    documentcode = p.documentcode,
    date = p.date,
    ...
    clientcod = clients.Select(j => j.clientcod).Where(u => clients.Select(c => c.TaxClienteID.ToString()).Contains(p.TaxClienteID)).ToString()
    }

    But I get this in the customer clientcod field:
    "System.Linq.Enumerable+WhereEnumerableIterator`1[System.String]"
    and I don't know how to extract the value.

    I'm sure there is a much simpler way, but I can't find it.
    someone can help me?

    OriginalGriffO J 2 Replies Last reply
    0
    • R Rui Couto

      Hi
      I'm trying to create a "FinalDocument" list from another list "OriginDocument"
      The problem is that the "FinalDocument" does not have the correct Client Code.
      So I want to get this Client Code from a third List "clients", for that I use the "TaxClienteID" field

      It would be something like this:

      List finalDocument = originDocument.Select(p => new FinalDocument()
      {
      documentcode = p.documentcode,
      date = p.date,
      ...
      codcliente = clients.codcliente where (TaxClienteID = clients.TaxClienteID)
      })

      I'm not getting it, the best I could get was with this:

      List finalDocument = originDocument.Select(p => new FinalDocument()
      {
      documentcode = p.documentcode,
      date = p.date,
      ...
      clientcod = clients.Select(j => j.clientcod).Where(u => clients.Select(c => c.TaxClienteID.ToString()).Contains(p.TaxClienteID)).ToString()
      }

      But I get this in the customer clientcod field:
      "System.Linq.Enumerable+WhereEnumerableIterator`1[System.String]"
      and I don't know how to extract the value.

      I'm sure there is a much simpler way, but I can't find it.
      someone can help me?

      OriginalGriffO Offline
      OriginalGriffO Offline
      OriginalGriff
      wrote on last edited by
      #2

      Try something like

      codcliente = clients.FirstOrDefault (c => p.TaxClienteID == c.TaxClienteID).clientcod

      Can't guarantee it, I have no idea of your classes or the interactions between them ...

      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!

      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
      "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

      R J 2 Replies Last reply
      0
      • OriginalGriffO OriginalGriff

        Try something like

        codcliente = clients.FirstOrDefault (c => p.TaxClienteID == c.TaxClienteID).clientcod

        Can't guarantee it, I have no idea of your classes or the interactions between them ...

        "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!

        R Offline
        R Offline
        Rui Couto
        wrote on last edited by
        #3

        thank you very much, it is working perfectly. Greetings

        OriginalGriffO 1 Reply Last reply
        0
        • R Rui Couto

          thank you very much, it is working perfectly. Greetings

          OriginalGriffO Offline
          OriginalGriffO Offline
          OriginalGriff
          wrote on last edited by
          #4

          You're welcome!

          "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!

          "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
          "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

          1 Reply Last reply
          0
          • OriginalGriffO OriginalGriff

            Try something like

            codcliente = clients.FirstOrDefault (c => p.TaxClienteID == c.TaxClienteID).clientcod

            Can't guarantee it, I have no idea of your classes or the interactions between them ...

            "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!

            J Offline
            J Offline
            James Curran
            wrote on last edited by
            #5

            That will give a null reference exception if p.TaxClienteID is not found in clients.

            Truth, James

            OriginalGriffO 1 Reply Last reply
            0
            • R Rui Couto

              Hi
              I'm trying to create a "FinalDocument" list from another list "OriginDocument"
              The problem is that the "FinalDocument" does not have the correct Client Code.
              So I want to get this Client Code from a third List "clients", for that I use the "TaxClienteID" field

              It would be something like this:

              List finalDocument = originDocument.Select(p => new FinalDocument()
              {
              documentcode = p.documentcode,
              date = p.date,
              ...
              codcliente = clients.codcliente where (TaxClienteID = clients.TaxClienteID)
              })

              I'm not getting it, the best I could get was with this:

              List finalDocument = originDocument.Select(p => new FinalDocument()
              {
              documentcode = p.documentcode,
              date = p.date,
              ...
              clientcod = clients.Select(j => j.clientcod).Where(u => clients.Select(c => c.TaxClienteID.ToString()).Contains(p.TaxClienteID)).ToString()
              }

              But I get this in the customer clientcod field:
              "System.Linq.Enumerable+WhereEnumerableIterator`1[System.String]"
              and I don't know how to extract the value.

              I'm sure there is a much simpler way, but I can't find it.
              someone can help me?

              J Offline
              J Offline
              James Curran
              wrote on last edited by
              #6

              This should be the "proper" version of what you want:

              void Main()
              {
              var originDocument = new List();
              var clients = new List();

              List finalDocument = 
              	(from p in originDocument
              	join c in clients on p.TaxClienteID equals c.TaxClienteID
              	select new FinalDocument
              	{
              		documentcode = p.documentcode,
              		date = p.date,
              		codcliente = c.codcliente
              	}).ToList();
              

              }

              class FinalDocument
              {
              public string documentcode { get; set; }
              public DateTime date { get; set; }
              public string codcliente { get; set; }
              public string TaxClienteID { get; set; }

              }

              class Client
              {
              public string codcliente { get; set; }
              public string TaxClienteID { get; set; }

              }

              Truth, James

              R 1 Reply Last reply
              0
              • J James Curran

                That will give a null reference exception if p.TaxClienteID is not found in clients.

                Truth, James

                OriginalGriffO Offline
                OriginalGriffO Offline
                OriginalGriff
                wrote on last edited by
                #7

                Yep. :-D I'm not doing all his work for him!

                "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!

                "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
                "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

                1 Reply Last reply
                0
                • J James Curran

                  This should be the "proper" version of what you want:

                  void Main()
                  {
                  var originDocument = new List();
                  var clients = new List();

                  List finalDocument = 
                  	(from p in originDocument
                  	join c in clients on p.TaxClienteID equals c.TaxClienteID
                  	select new FinalDocument
                  	{
                  		documentcode = p.documentcode,
                  		date = p.date,
                  		codcliente = c.codcliente
                  	}).ToList();
                  

                  }

                  class FinalDocument
                  {
                  public string documentcode { get; set; }
                  public DateTime date { get; set; }
                  public string codcliente { get; set; }
                  public string TaxClienteID { get; set; }

                  }

                  class Client
                  {
                  public string codcliente { get; set; }
                  public string TaxClienteID { get; set; }

                  }

                  Truth, James

                  R Offline
                  R Offline
                  Rui Couto
                  wrote on last edited by
                  #8

                  Thanks James, this code was very useful Regards Rui

                  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