Linq to a Class with ListClass

0

I have a question, I am a bit new to this Linq, and I need your help.

public class getHistorialInstalaciones
    {
        public string end_date { get; set; }
        public udataHistorialInteracciones udata { get; set; }
        public fromHistorialInteracciones from { get; set; }
        public List<toHistorialInteracciones> to { get; set; }
    }

And I want to make a query with Linq that I do it like this Cases = to Deserialization in Json to the Class.

var Lista = (from r in casos
             select new
                 {
                     //toI = r.udata.To,
                     //toII = r.to,
                     //fromI = [email protected],
                     end_dateI = r.end_date,
                 }).ToList();

But I also need to bring me the value of to , from and udata.to .

How can I consult these fields?

    
asked by Spyros Capetanopulos Demarco 07.04.2017 в 15:36
source

2 answers

0

Assuming that casos is of type List<getHistorialInstalaciones> you just have to put to what type you want that object to be added, in this case select new getHistorialInstalaciones { ... } :

var Lista = (from r in casos
    select new getHistorialInstalaciones
    {
         to = r.udata.To, // también puede ser "to = r.To", depende del que necesites
         fromI = [email protected],
         end_date = r.end_date,
    }).ToList();
    
answered by 07.04.2017 в 17:52
0

Because you need to make a linq that transforms the data if you could use JsonProperty to indicate a field that is different from json.

If you use Json.NET you could implement

public class getHistorialInstalaciones
{
    [JsonProperty(PropertyName = "end_date")]
    public string end_dateI  { get; set; }

    [JsonProperty(PropertyName = "udata")]
    public udataHistorialInteracciones toI { get; set; }

    [JsonProperty(PropertyName = "from")]
    public fromHistorialInteracciones fromI { get; set; }

    [JsonProperty(PropertyName = "to")]
    public List<toHistorialInteracciones> toII { get; set; }
}

then when deserialices map with the properties of the json property but your class will have the ones you define, in this way you do not need to convert

.Net NewtonSoft Json Deserialize map to a different property name

    
answered by 07.04.2017 в 18:25