Windows Azure Storage (6) Windows Azure Storage之Table
《Windows Azure Platform 系列文章目录》
最近想了想,还是有必要把Windows Azure Table Storage 给说清楚。
1.概念
Windows Azure Table是存储在云端的非关系型数据表,主要存储结构化数据,简单理解上来是类似SQL Server的一张单表,包含了列名和行数据,但是无法执行关系型运算(e.g. inner join)。在某些场景,比如只纪录系统运行日志、用户操作日志等场景下,比较适合使用Table Storage。
使用Table Storage,除了设置账户信息(Account Name和Access Key)以外,还需要设置TableName。TableName就是存储的数据表。(比如我可以使用Product来存储产品信息数据,使用Client来存储用户信息数据,这个概念和SQL Server非常类似)。
Table Service 主要是存储结构化数据的,所有的数据都是一个个 Entity,多个 Entity 在一起作为一个 Table。而每一个 Entity 中最多包含 255 个 Property。每个 Property 以键值对(Key-Value Pair)的方式保存,Key 是字符串类型而 Value 可以是任意的.NET 标准类型,比如字符串、整型、日期等。但是,Storage Service 要求每一个 Entity 必须包含下面三个 Property:Partition Key、Row Key和 Timestamp。
-PartitionKey设置了Table中数据的分区规则。比如下图中
前2行数据具有相同的Partition Key,名为Examples Doc。那前2行数据在物理存储上是在同一个存储节点上(比如同一个磁盘上)。
后2行数据具有相同的Partion key(FAQ Doc)。那后面3行的数据在物理存储上也是在同一个存储节点上的。(可能与上面的Example Doc存储在同一个节点上)
这样的架构设计好处在于:
1.当存储在Table中的数据访问量少的时候,Windows Azure会把Example Doc的数据和FAQ Doc的数据放在同一个存储上。
2.当访问FAQ Doc的用户逐渐增多的时候,Windows Azure会把FAQ Doc的数据单独迁移到某一存储上,加快访问速度。
-RowKey 是识别Table 行数据的唯一标识符。
对于相同的Partition Key的行数据来说,他们的RowKey必须是唯一的。
一般情况下,我们可以使用GUID来设置RowKey。
Partition Key 和 Row Key 可以作为 Entity 的联合主键。
-TimeStamp
DateTime类型,这个属性是由系统维护的,用户无法修改。表示该行数据的最后操作时间。
2.我们使用管理员身份运行VS2013。新建Cloud Project,并且重命名为AzureStorageTable
3.添加ASP.NET Web Role
4.展开AzureStorageTable,展开Roles,右键WebRole1。在Settings添加StorageConnectionString,并设置相应的Value
5.在WebRole1 Project中,修改Global.asax.cs代码如下:
using Microsoft.WindowsAzure; using Microsoft.WindowsAzure.Storage; using Microsoft.WindowsAzure.Storage.Table; using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Routing; using System.Web.Security; using WebRole1;namespace WebRole1 {public class Global : HttpApplication{void Application_Start(object sender, EventArgs e){// Code that runs on application startup AuthConfig.RegisterOpenAuth();RouteConfig.RegisterRoutes(RouteTable.Routes);//Initialize Table FirstCloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString"));CloudTableClient tableClient = storageAccount.CreateCloudTableClient();CloudTable table = tableClient.GetTableReference("Message");table.CreateIfNotExists();}void Application_End(object sender, EventArgs e){// Code that runs on application shutdown }void Application_Error(object sender, EventArgs e){// Code that runs when an unhandled error occurs }} }
6.修改Default.aspx,增加TextBox和Button。修改后的界面如下:
7.在Default.aspx.cs里,增加引用如下:
using Microsoft.WindowsAzure; using Microsoft.WindowsAzure.Storage; using Microsoft.WindowsAzure.Storage.Table;
8.增加Button_Click事件
protected void btnAddMessage_Click(object sender, EventArgs e){// Retrieve the storage account from the connection string.CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString"));// Create the table client.CloudTableClient tableClient = storageAccount.CreateCloudTableClient();// Create the CloudTable object that represents the "people" table.CloudTable table = tableClient.GetTableReference("Message");// Create a new Message entity.MessageEntity message1 = new MessageEntity();message1.Detail = txbMessage.Text;// Create the TableOperation that inserts the customer entity.TableOperation insertOperation = TableOperation.Insert(message1);// Execute the insert operation. table.Execute(insertOperation);}
9. MessageEntity的定义如下:
using System; using System.Collections.Generic; using System.Linq; using System.Web; using Microsoft.WindowsAzure.Storage.Table;namespace WebRole1 {public class MessageEntity : TableEntity{public MessageEntity(){PartitionKey = "Message";RowKey = Guid.NewGuid().ToString();}public string Detail { get; set; }} }
10.运行VS2013调试。在输入框中输入相应的内容,并点击按钮。如下图:
10.点击按钮完毕后,我们回到VS2013,点击菜单栏的VIEW->Server Explorer
11.在Server Explorer中,展开Windows Azure,Storage。选择相应的Storage Table,就可以查看到我们插入成功的数据。
转载于:https://www.cnblogs.com/threestone/p/3406259.html
Windows Azure Storage (6) Windows Azure Storage之Table相关推荐
- Windows Azure Storage (4) Windows Azure Storage Service存储服务之Blob Share Access Signature
<Windows Azure Platform 系列文章目录> 如果读者使用的是国内由世纪互联运维的Azure China服务,请参考笔者的博文Azure China (4) 管理Azur ...
- Windows Azure Storage (3) Windows Azure Storage Service存储服务之Blob详解(中)
<Windows Azure Platform 系列文章目录> 如果读者使用的是国内由世纪互联运维的Azure China服务,请参考笔者的博文Azure China (4) 管理Azur ...
- Windows Azure Storage (1) Windows Azure Storage Service存储服务
<Windows Azure Platform 系列文章目录> 如果读者使用的是国内由世纪互联运维的Azure China服务,请参考笔者的博文Azure China (4) 管理Azur ...
- Azure Table storage 基本用法 -- Azure Storage 之 Table
Azure Storage 是微软 Azure 云提供的云端存储解决方案,当前支持的存储类型有 Blob.Queue.File 和 Table,其中的 Table 就是本文的主角 Azure Tabl ...
- Azure Blob Storage 基本用法 -- Azure Storage 之 Blob
Azure Storage 是微软 Azure 云提供的云端存储解决方案,当前支持的存储类型有 Blob.Queue.File 和 Table. 笔者在<Azure Table storage ...
- 【Microsoft Azure 的1024种玩法】四十二. 通过Windows Admin Center快速创建Azure Virtual Machines
[简介] Windows Admin Center是微软开发的一套可以部署在本地基于浏览器的GUI的工具集平台,其平台可用于管理Windows相关服务器和PC机器,我们可以利用Windows Admi ...
- Azure File Storage 基本用法 -- Azure Storage 之 File
Azure Storage 是微软 Azure 云提供的云端存储解决方案,当前支持的存储类型有 Blob.Queue.File 和 Table. 笔者在<Azure Blob Storage 基 ...
- 详细故障排除步骤:针对 Azure 中到 Windows VM 的远程桌面连接问题
本文提供详细的故障排除步骤,用于为基于 Windows 的 Azure 虚拟机诊断和修复复杂的远程桌面错误. Important 若要消除更常见的远程桌面错误,请务必先阅读远程桌面的基本故障排除文章, ...
- Azure 上使用 Windows Server Core 运行 ASP.NET Core 网站
点击上方蓝字关注"汪宇杰博客" 导语 微软智慧云 Azure 上虽然早就有 App Service 这种完全托管的 PaaS 服务可以让我们分分钟建网站.但是不自己配一下环境,就不 ...
最新文章
- java 获取linux mac_java在linux获得ip地址和mac
- 软件工程第二次作业完整版
- 小菜的 VUE 使用技巧 持续更新
- android merge的作用,Android学习手记-merge
- Redis高级项目实战!北京java编程入门培训
- DecimalFormat 用法
- linux分区表导出与恢复,Linux下硬盘数据恢复与分区表恢复
- idea卸载删除旧版重新安装新版后,新版本idea程序打不开闪退的解决方案
- android MVP框架
- 《2019年数据及存储发展研究报告》十大洞察
- python扫描字符串文本时下线_SyntaxError:扫描字符串文本Python calcun时的EOL
- TracePro小白学习操作
- 来啦!iphone ios免越狱,个性化修改微信提示音!
- ie edge浏览记录文件_如何在Microsoft Edge中清除浏览历史记录
- 【台达 PLC - 1】 - 编程软件(WPL)
- ie8css无效,CSS 伪类在IE8中样式无法生效
- 逻辑斯谛回归(logistic regression)
- xlistview的使用
- 你知道PDF怎么合并吗?这些技巧快来码住
- Unity之ASE从入门到精通 目录
热门文章
- C++入门课程系列:基础知识篇(1)
- 【原创】packetbeat 之“request-response 错误关联”问题
- centos6.5 做路由器
- PHP性能如何实现全面优化?
- linux的用户管理与权限学习总结
- WPF不同线程之间的控件的访问
- Android应用程序键盘(Keyboard)消息处理机制分析(26)
- Android JNI(Java Native Interface)技术介绍
- android 获取控件在屏幕中的坐标
- 公司app 从兼容Android 8.0 升级兼容9.0