I have the following serializable class:
[Serializable]
public class EmailClass
{
public string from;
public List<string> To;
public List<string> CC;
public string DisplayTo;
public string Subject { get; set; }
public int attachments;
public List<string> attachmentsName;
public string DateTimeReceived;
public string DateTimeSent;
public string FinalFilename;
public string DatetimeCreated;
public string ExchangeUniqueId;
public string ChankeyID;
public string FinalFileName {get;set;}
public bool Encrypted;
public string Descripcion { get; set; }
}
So know, I have a List and I want to query it using Linq:
var query = from p in listado
where p.from.ToString().ToUpper() == textBox1.Text
And the problem is that it recognizes the p.from
as the linq from identifier, so it
is not accepted.
Error: Invalid expression term 'from'
I can not change the class public string "from" because it is deserializing xml objects stored in hard disk.
How could I work around this problem?
I know I could use List.FindAll or something like that, but I would really like to know if I can do it using linq.
Change where p.from.ToString()
to where [email protected]()
. You are using from
as both a keyword and identifier.
David Arno has shown how to avoid conflicts with keywords via @from
, however:
I can not change the class public string "from" because it is deserializing xml objects stored in hard disk.
As an alternative approach:
[XmlElement("from")]
public string From {get;set;}
This tells XmlSerializer
how to map the name; then you can use:
var query = from p in listado
where p.From.ToUpper() == textBox1.Text
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With