Is there a limit to subclass levels to use the Where function for query?

Asked

Viewed 39 times

1

I am working on an internal statistical data system of my company and I came across a situation I had never seen before.

I am consulting the API of a service and this returns me a JSON with many entries and sub-entries. I converted this JSON into C# classes and started working on the information filters. It happens that if I make a filter using the WHERE function in a list in the fields of the first level the return is correct. However, if I do this on internal levels, I get an exception.

The classes of the created objects were:

    public class Associations
    {
        public List<int> associatedVids { get; set; }
        public List<object> associatedCompanyIds { get; set; }
        public List<object> associatedDealIds { get; set; }
        public List<object> associatedTicketIds { get; set; }
    }

    public class DealnameVersions
    {
        public string name { get; set; }
        public string value { get; set; }
        public long timestamp { get; set; }
        public string sourceId { get; set; }
        public string source { get; set; }
        public List<object> sourceVid { get; set; }
    }

    public class Dealname
    {
        public string value { get; set; }
        public long timestamp { get; set; }
        public string source { get; set; }
        public string sourceId { get; set; }
        public List<DealnameVersions> versions { get; set; }
    }

    public class HubspotOwnerIdVersions
    {
        public string name { get; set; }
        public string value { get; set; }
        public object timestamp { get; set; }
        public string sourceId { get; set; }
        public string source { get; set; }
        public List<object> sourceVid { get; set; }
        public string requestId { get; set; }
    }

    public class HubspotOwnerId
    {
        public string value { get; set; }
        public long timestamp { get; set; }
        public string source { get; set; }
        public string sourceId { get; set; }
        public List<HubspotOwnerIdVersions> versions { get; set; }
    }

    public class DealstageVersions
    {
        public string name { get; set; }
        public string value { get; set; }
        public object timestamp { get; set; }
        public string sourceId { get; set; }
        public string source { get; set; }
        public List<object> sourceVid { get; set; }
    }

    public class Dealstage
    {
        public string value { get; set; }
        public long timestamp { get; set; }
        public string source { get; set; }
        public string sourceId { get; set; }
        public List<DealstageVersions> versions { get; set; }
    }

    public class CidadeDeInteresseVersions
    {
        public string name { get; set; }
        public string value { get; set; }
        public long timestamp { get; set; }
        public string sourceId { get; set; }
        public string source { get; set; }
        public List<object> sourceVid { get; set; }
    }

    public class CidadeDeInteresse
    {
        public string value { get; set; }
        public long timestamp { get; set; }
        public string source { get; set; }
        public string sourceId { get; set; }
        public List<CidadeDeInteresseVersions> versions { get; set; }
    }

    public class Properties
    {
        public Dealname dealname { get; set; }
        public HubspotOwnerId hubspot_owner_id { get; set; }
        public Dealstage dealstage { get; set; }
        public CidadeDeInteresse cidade_de_interesse { get; set; }
    }

    public class Deal
    {
        public int portalId { get; set; }
        public int dealId { get; set; }
        public bool isDeleted { get; set; }
        public Associations associations { get; set; }
        public Properties properties { get; set; }
        public List<object> imports { get; set; }
        public List<object> stateChanges { get; set; }
    }

    public class DealsModel
    {
        public List<Deal> deals { get; set; }
        public bool hasMore { get; set; }
        public int offset { get; set; }
    }

The filters I’m doing this way:

reservationList.Where(x => x.properties.dealstage.value == funilItem.stageId);

Note the expression passing through the properties object, then the dealstage object and comparing with the value field.

In this format I have failed. An exception is generated with the following information:

'reservationList.Findall(x => x.properties.dealstage.value == funilItem.stageId)' threw an Exception of type 'System.Nullreferenceexception'

inserir a descrição da imagem aqui

However, if you do the same query format only in the fields at the same level of properties, the process is performed successfully.

reservationList.Where(x => x.dealId == funilItem.stageId);

Now I ask. Is there any limitation with subclass levels or is there something more wrong with my code? How should I solve this problem?

I would like to take all Deals based on the "value" field contained within properties -> dealstage -> value.

Thank you very much in advance.

  • There is no limitation. Specify better what you mean by "failing" that you may be able to help.

  • What is the exception?

  • Follows exception and a print referring to all the data of it. But only for alignment, the list is not empty. I have already checked and it has data.

  • 1

    Maybe you are trying to access the property of an object that has not been instantiated

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.