0
votes

I'm trying to get all the rows from an azure storage table, but when i display them all the values except PartitionKey and RowKey are null or 0. Am i missing something or am i doing something wrong causing all the values to not get read properly?

This is the code i used to get all the data.

 List<Employe> employeList = new List<Employe>();
 TableQuery<Employe> query = new TableQuery<Employe>();
 employeList = table.ExecuteQuery(query).ToList();

This is the model.

class Employe:TableEntity
    {
        public string prenume { get; set; }
        public string functie  { get; set; }
        public int salar_baza { get; set; }
        public int retineri { get; set; }
        public int spor { get; set; }
        public int total_brut { get; set; }
        public int brut_impozabil { get; set; }
        public int impozit { get; set; }
        public int cas { get; set; }
        public int cass { get; set; }
        public int virat_card { get; set; }
        public  int premii_brute { get; set; }

        public Employe()
        {
        }
        public Employe(string nr_crt, string name,string prename,string function, int salarBaza,int retinere,int sporuri,int premiu_burt)
        {
            PartitionKey = nr_crt;
            RowKey = name;
            this.prenume = prename;
            this.functie = function;
            this.salar_baza = salarBaza;
            this.retineri = retinere;
            this.spor = sporuri;
            this.premii_brute = premiu_burt;

            this.total_brut = salarBaza+(salarBaza*(sporuri/100))+premiu_burt;
            this.cas = (25/100)*total_brut;
            this.cass = (10/100)*total_brut;
            this.brut_impozabil = total_brut-cas-cass;
            this.impozit = (10/100)*brut_impozabil;
            this.virat_card =total_brut-impozit-cas-cass-retinere;
        }
    }
1

1 Answers

1
votes

I haven't tested this myself, but I'm pretty sure this applies:

When using the TableQuery and it's built-in deserializer, it uses the parameterless constructor public Employe() to create a new, empty object. Then it tries to find matching properties but their name. But since all your properties have names that differ from the values in your table storage, none of them get set.

So either, rename your properties to match your storage (e.g rename public string prenume to public string prename) or, work with annotations on your properties such as these.