【问题标题】:Null values when reading rows from azure table从天蓝色表中读取行时为空值
【发布时间】:2020-06-30 13:55:58
【问题描述】:

我正在尝试从 azure 存储表中获取所有行,但是当我显示它们时,除了 PartitionKey 和 RowKey 为 null 或 0。是我遗漏了什么还是我做错了什么导致所有值无法正确读取?

这是我用来获取所有数据的代码。

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

这是模型。

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;
        }
    }

【问题讨论】:

    标签: azure azure-tablequery


    【解决方案1】:

    我自己没有对此进行测试,但我很确定这适用:

    当使用 TableQuery 和它的内置反序列化器时,它使用无参数构造函数 public Employe() 创建一个新的空对象。然后它尝试查找匹配的属性,但它们的名称。但是由于所有属性的名称都与表存储中的值不同,因此它们都不会被设置。

    因此,要么重命名您的属性以匹配您的存储(例如,将 public string prenume 重命名为 public string prename),或者使用您的属性上的注释,例如 these

    【讨论】:

    • 想通了,我的天蓝色表中的列名需要与我的参数名相同。谢谢
    猜你喜欢
    • 2020-10-05
    • 2018-09-15
    • 2021-07-21
    • 1970-01-01
    • 1970-01-01
    • 2021-06-29
    • 1970-01-01
    • 2019-07-19
    • 2019-10-31
    相关资源
    最近更新 更多