Azure

Insert Information Into Azure Desk Storage Utilizing ASP.NET Core Software

Immediately, on this article we’ll talk about the best way to develop an online software or console-based software to retailer knowledge into the Azure Desk Storage. Now, as everyone knows, Desk Storage is part of the Azure Storage. So, first, we’ll talk about some fundamental ideas about Azure desk storage after which we’ll talk about the best way to retailer knowledge into the Azure desk storage.

 

Microsoft offers 4 various kinds of storage throughout the Azure Storage aside from Azure SQL and Azure Cosmos DB. Azure Storage accounts present 4 various kinds of knowledge companies by way of which we will save knowledge into the Azure storage accounts. The under picture reveals all the weather of Azure Storage.

 

Idea of Azure Desk Storage

 

Azure Desk Storage is used to construction NoSql Information. With the assistance of Azure Desk Storage, we will retailer a considerable amount of structured knowledge. The Azure Desk Storage is a NoSQL knowledge service that at all times accepts authenticated calls both from Azure Cloud-based functions or exterior functions. We will use Azure Tables for storing structured, non-relational knowledge. Among the frequent makes use of of the Azure Desk Storage are,

  1. It might retailer TBs of structured NoSQL primarily based knowledge for service web-scale functions
  2. It might retailer datasets that don’t require complicated joins, international keys, or saved procedures and might be denormalized for quick entry.
  3. It might shortly be querying knowledge utilizing a clustered index
  4. We will entry the information of Azure Desk Storage utilizing the OData protocol and LINQ queries with the assistance of WCF Information Service and .Internet Libraries.
  5. To Add Information, we simply have to have the Storage Explorer or add knowledge through a .Internet program.

If we graphically signify the Azure Desk Storage, then the Picture will likely be as under,

 

Insert Data Into Azure Table Storage Using ASP.NET Core Application

Azure Desk storage at all times incorporates the next elements,

  1. URL Format
    Each Azure Desk Storage Objects at all times has an URL kind entry level like http://<storage account>.desk.core.home windows.internet/<desk>. We will entry the Azure desk through these URLs with the assistance of the OData Protocol.
  2. Accounts
    Each Azure Desk Storage object should be part of the Azure Storage accounts.
  3. Desk
    A desk at all times represents both a set of entities or a single entity. There isn’t a requirement of defining a schema for outlining the Desk. So, it implies that we will retailer knowledge with a special set of properties throughout the Desk.
  4. Entity
    Entity means a set of knowledge with a single or a number of properties. It’s simply much like the Database row. In Azure, usually every entity might be saved knowledge as much as 1 MB Dimension.
  5. Properties
    A property is a name-value pair. We will outline as much as 252 completely different properties inside a single entity. Excluding the user-defined properties, every entity at all times incorporates three default system generated properties particularly Partition Key, Row Key, and a Timestamp. Entities that include the identical partition key will likely be fetched sooner once we run any question operation in opposition to the Azure Desk Storage. Within the entity, the row key’s the distinctive identifier throughout the partition key values.
Insert Data Into Azure Table Storage Using ASP.NET Core Application

Perquisites Required

  • Microsoft Visual Studio 2017
  • The account in Azure Portal.

Should you don’t have any current Azure account, then you’ll be able to create a free trial account within the Azure portal utilizing your electronic mail id.

 

The right way to Create an Azure Storage Account?

 

To create the Azure Storage Account in Azure Portal, first, we have to login to the Azure Portal after which carry out the under steps to create an Azure Storage Account.

 

Step 1

 

Click on on the Azure Storage Accounts choice from the Useful resource Dashboard

 

Insert Data Into Azure Table Storage Using ASP.NET Core Application

 

Step 2

 

On the Create Azure Storage Account, Click on on the Add Button within the Storage Account Web page.

 

Step 3

 

Now, present the associated required info to create an Azure Storage Account.

 

Insert Data Into Azure Table Storage Using ASP.NET Core Application

 

Step 4

 

Within the above picture, Storage Account Identify means Account Identify. Additionally, Choose Storage V2 choices to avail the service of all 4 knowledge companies of Azure Storage Accounts.

 

Step 5

 

Now click on on evaluation and create choice.

 

Step 6

 

After the settings are validated, click on Create to create the account

 

Step 7

 

As soon as the deployment is succeeded, click on Go to useful resource choices to open Storage Account.

 

Insert Data Into Azure Table Storage Using ASP.NET Core Application

 

Step 8

 

As soon as Storage Account is created, click on on Entry Keys choices of the left panel and duplicate the ConnectionString worth. This worth must be offered in our net software in order that we will add recordsdata in Azure blob storage.

 

Insert Data Into Azure Table Storage Using ASP.NET Core Application

 

Create Console Software Utilizing Asp.Internet Core in VS 2019

 

Step 1

 

Now open Microsoft Visual Studio 2017 and click on on File -> New -> Tasks.

 

Step 2

 

Choose Console App Mission template and Click on on Okay Button

 

Step 3

 

Now, we have to set up the under Nuget Packages to entry Azure storage account utilizing Microsoft Azure Storage Cosmos Desk shopper driver.

 

Insert Data Into Azure Table Storage Using ASP.NET Core Application

 

Step 4

 

Now, first, we have to set up communication between our software and the Azure Storage account. For that function, we’ll create a CloudStorageAccount occasion and parse the connection string to the category occasion. After it, we have to create the occasion of CloudTableClient in order that we will set up a reference to Azure Storage accounts. Now after this, we have to create an occasion of CloudTable which is able to present us a reference of Desk Objects within the Azure Desk storage.

  1. static string storageconn = “DefaultEndpointsProtocol=https;AccountName=demofilestoragesamples20;AccountKey=fw/Z6ou//OXhfIvwe8fZsHna3yJrW92iGOSJH/3hGkekhtxmg==;EndpointSuffix=core.home windows.internet”;  
  2.   
  3.         static string table1 = “Worker”;  
  4.         static string partitionkey = “Debasis Saha”;  
  5.         static string rowKey = “userC”;  
  6.          
  7.         static void Primary(string[] args)  
  8.         {  
  9.             CloudStorageAccount storageAcc = CloudStorageAccount.Parse(storageconn);  
  10.             CloudTableClient tblclient = storageAcc.CreateCloudTableClient(new TableClientConfiguration());  
  11.             CloudTable desk = tblclient.GetTableReference(table1);  
  12.   
  13.             Console.ReadKey();  
  14.         }  

Step 5

 

Now, first, we’ll attempt to insert a single document into the Azure Desk Storage named Worker. For that function, we’ll create the under methodology:-

  1. public static async Process<string> InsertTableEntity(CloudTable p_tbl)  
  2. {  
  3.     Worker entity = new Worker(“Debasis Saha”“userC”);  
  4.     entity.Wage = 50000;  
  5.     TableOperation insertOperation = TableOperation.InsertOrMerge(entity);  
  6.     TableResult end result = await p_tbl.ExecuteAsync(insertOperation);  
  7.     Console.WriteLine(“Worker Added”);  
  8.     return “Worker added”;  
  9. }  

Step 6

 

Now run the appliance after which examine the Storage Explorer within the Azure Portal:-

 

Insert Data Into Azure Table Storage Using ASP.NET Core Application

 

Step 7

 

Now, if we wish to insert bulk knowledge then we will use the under methodology,

  1. public static async Process<string> InsertBatch(CloudTable p_tbl)  
  2. {  
  3.     TableBatchOperation l_batch = new TableBatchOperation();  
  4.       
  5.     Worker entity1 = new Worker(“Swapan Sharma”“user1”);  
  6.     entity1.Wage = 35000;  
  7.     Worker entity2 = new Worker(“Swapan Sharma”“userB”);  
  8.     entity2.Wage = 20000;  
  9.     Worker entity3 = new Worker(“Swapan Sharma”“userC”);  
  10.     entity3.Wage = 30000;  
  11.     l_batch.Insert(entity1);  
  12.     l_batch.Insert(entity2);  
  13.     l_batch.Insert(entity3);  
  14.     p_tbl.ExecuteBatch(l_batch);  
  15.     Console.WriteLine(“Information Inserted”);  
  16.     return “Accomplished”;  
  17. }  

Step 8

 

Now after executing this system, examine the Storage Explorer to view the information.

 

Insert Data Into Azure Table Storage Using ASP.NET Core Application

 

Step 9

 

Now, if we wish to question the desk in opposition to any specific partition key, then the under methodology must be executed-

  1. public static async Process<string> Question(CloudTable p_tbl)  
  2.         {  
  3.   
  4.             TableQuery<Worker> CustomerQuery = new TableQuery<Worker>().The place(  
  5.                 TableQuery.GenerateFilterCondition(“PartitionKey”, QueryComparisons.Equal, “Swapan Sharma”  
  6.                 ));  
  7.             var itemlist = p_tbl.ExecuteQuery(CustomerQuery);  
  8.             foreach (Worker obj in itemlist)  
  9.             {  
  10.                 Console.WriteLine(“The Worker Identify is “ + obj.PartitionKey);  
  11.                 Console.WriteLine(“The Consumer Identify is “ + obj.RowKey);  
  12.                 Console.WriteLine(“The Wage is “ + obj.Wage);  
  13.             }  
  14.             return “Operation full”;  
  15.         }  

Step 10

 

Now run this system to examine the output,

 

Insert Data Into Azure Table Storage Using ASP.NET Core Application

 

Conclusion

 

On this article, we mentioned the best way to retailer knowledge utilizing the Asp.Internet Core software in Azure Desk Storage. Any solutions or suggestions or question associated to this text are most welcome.

Show More

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button