Lists C#
-
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" fieldIt 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? -
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" fieldIt 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?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!
-
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!
-
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!
-
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!
That will give a null reference exception if p.TaxClienteID is not found in clients.
Truth, James
-
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" fieldIt 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?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
-
That will give a null reference exception if p.TaxClienteID is not found in clients.
Truth, James
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!
-
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