非派生POCO和Azure存储 [英] Non-derived POCO and Azure Storage

查看:68
本文介绍了非派生POCO和Azure存储的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以为Azure表存储使用非派生的POCO?

Is it possible to have a non-derived POCO for Azure Table Storage?

换句话说,不是从TableEntity派生或实现ITableEntity的POCO?

In other words, a POCO that does not derive from TableEntity or implement ITableEntity?

必须要有一个依赖于接口或基类的模型,这似乎倒退了一步,因为这会导致引用在链中向上泄漏-我无法在无需了解Azure的情况下在另一层中建立模型接口或基类的存储!

It seems a step backward to have to have a model which is dependent on the interface or base class, as this causes reference leaks upward in the chain - I cannot set up the model in another tier without it having to know about Azure Storage for either the interface or the base class!

推荐答案

看看

Take a look at DynamicTableEntity (ctrl+f for it). It can be used to query and insert entities.

使用这种类型,您不会在域模型中引入任何依赖关系,但是您将必须自己将POCO转换为DynamicTableEntity –尽管您愿意使用以下方式标记POCO,但该过程可以轻松实现自动化一个自定义界面并编写一个映射器(基本上,您只需要一个属性字典+需要知道最重要的是Partition/RowKey).

Using this type, you won't introduce any dependencies intor your Domain Model, however you will have to convert a POCO to a DynamicTableEntity by yourself – this process can easily be automated though if you're willing to flag your POCOs with a custom interface and write a mapper (basically you just need a dictionary of properties + need to know wich ones are Partition/RowKey).

您不能只在Azure Table Storage中保存任何实体的原因是,它需要知道哪个属性充当分区密钥,而哪个属性充当行密钥.必须在较低级别"上使用DynamicTableEntity的好处是,您可以创建仅返回属性子集的查询,以减少资源消耗.这可能对您有好处,也可能没有好处.

The reason why you can't just save any entity in Azure Table Storage is that it needs to know which property acts as Partition Key and wich as Row Key. The upside of having to work with DynamicTableEntity on a "lower level" is that you can create queries that return only a subset of properties which reduces resource consumption. This may or may not be beneficial in your case.

这篇关于非派生POCO和Azure存储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆