简体   繁体   English

azure 本地存储表自定义字段为 null

[英]azure local storage table custom fields are null

I am trying to create a generic insert method, I generate a class from the abstract TableEntity class.我正在尝试创建一个通用插入方法,我从抽象 TableEntity class 生成一个 class。

    class STCompany : TableEntity {
        string Abbrev;
        string Name;
        string NavName;

        public STCompany(
            string partitionKey, string rowKey, DateTime timeStamp,
            string abbrev, string name, string navName
        )
        {
            PartitionKey = partitionKey;
            RowKey = rowKey;
            Timestamp = timeStamp;
            Abbrev = abbrev;
            Name = name;
            NavName = navName;
        }

    }

attempt to create a generic insert method in this static class (see Insert Task at the bottom of codeblock)尝试在此 static class 中创建通用插入方法(请参阅代码块底部的插入任务)

    public static class lclStorage
    {
        private static string paramsConstring = __paramsConstring;
        private static CloudStorageAccount storageAcc;
        private static CloudTableClient tblclient;
        private static CloudTable get_params_table (string table_name){
            if(storageAcc == null) storageAcc = CloudStorageAccount.Parse(paramsConstring);  
            if(tblclient == null) tblclient = storageAcc.CreateCloudTableClient(new TableClientConfiguration());
            return tblclient.GetTableReference(table_name);
        }


        public static class cloudTables{
            public static CloudTable AccessUsersShareholders = get_params_table("AccessUsersShareholders");
            public static CloudTable CompanyPropertyMapping = get_params_table("CompanyPropertyMapping");
            public static CloudTable STCompanies = get_params_table("STCompanies");
            public static CloudTable STdepartments = get_params_table("STdepartments");
        }

        public static async Task<(int statusCode, string response, bool success)> Insert(CloudTable p_tbl, TableEntity te)  
        {  
            TableOperation insertOperation = TableOperation.InsertOrMerge(te);  
            TableResult result = await p_tbl.ExecuteAsync(insertOperation);  

            Console.WriteLine("Record Added");  
            return (
                result.HttpStatusCode, 
                (result.HttpStatusCode == 204) ? "Record added" : "Failed to add record", 
                result.HttpStatusCode == 204);  
        }  
        
    }

In my main program I then run the Insert然后在我的主程序中运行插入

      var result = await lclStorage.Insert( 
          lclStorage.cloudTables.STCompanies,
          new STCompany( "STCompanies", "TE3", DateTime.Now, "TE3", "test", "nav__test")
      );
      Console.WriteLine($"{result.response} __ {result.success}");

In TableResult result the fields are displayed correctlyTableResult result中,字段显示正确在此处输入图像描述

But in my Azure table the fields Abbrev, Name and NavName are set to null.但是在我的 Azure 表中,字段 Abbrev、Name 和 NavName 设置为 null。 在此处输入图像描述 Is this caused by the fact that I declared TableEntity as the type instead of STCompany in my insert function or am I doing something else wrong?这是由于我在插入TableEntity中将 TableEntity 声明为类型而不是STCompany还是我做错了什么?

So the variables Abbrev,Name,NavName in the TableEntity class must be public.所以 TableEntity class 中的变量Abbrev,Name,NavName NavName 必须是公共的。

    class STCompany : TableEntity {
            public string Abbrev { get; set; }
            public string Name { get; set; }
            public string NavName { get; set; }

        public STCompany(
            string partitionKey, string rowKey,
            string abbrev, string name, string navName
        )
        {
            PartitionKey = partitionKey;
            RowKey = rowKey;
            Abbrev = abbrev;
            Name = name;
            NavName = navName;
        }

    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM