简体   繁体   English

动态/自定义属性

[英]dynamic/custom properties

I would like to use dynamic properties, which look like this: 我想使用动态属性,如下所示:

public class CustomProperty
{
  public string PropType { get; set; }
  public string PropValue { get; set; }
  public string PropName { get; set; }
  ...
}

...and then save these properties to a database, like this: ...然后将这些属性保存到数据库中,如下所示:

PropType   PropValue   PropName
--------   ---------   --------
String     "William"   "Name"
Int64      "21"        "Age"
String     "John"      "Name"
Int64      "32"        "Age"
String     "Brown"     "Haircolor"
...

I don't think I'm the first to have an idea like this, so I'm looking for an implementation (poen source / nuget etc.). 我不认为我是第一个拥有这种想法的人,因此我正在寻找实现方案(便笺源/ nuget等)。 But I have trouble finding one. 但是我很难找到一个。

So my question is: is there an implemenation of dynamic properies which can be used (or improved if needed)? 所以我的问题是:是否存在可以使用(或必要时进行改进)的动态属性?

Edit: As richardtallent pointer out, I'm looking for the EAV pattern. 编辑:作为理财指针,我正在寻找EAV模式。 So, is there an implentation for it that can be used? 那么,有没有可以使用的功能呢? Or do I have to write something myself. 还是我必须自己写点东西。 I would think it has been done many times before. 我认为以前已经做过很多次了。

What you are describing is often called an "EAV" (Entity-Attribute-Value) pattern. 您所描述的通常称为“ EAV”(实体-属性-值)模式。

Many consider it an anti-pattern when applied to relational databases since using it has implications for maintaining proper normalized data and efficient CRUD operations. 许多人在将其应用于关系数据库时都将其视为反模式,因为使用它会对维护适当的规范化数据和有效的CRUD操作产生影响。 However, it does have its uses. 但是,它确实有其用途。

Variations on this theme are used in No-SQL databases ranging from Lotus Notes to Google BigTable. 从Lotus Notes到Google BigTable,在No-SQL数据库中使用了有关此主题的变体。 So if you're not tied to using SQL Server, your best bet might be to look into C#-accessible No-SQL databases such as MongoDB. 因此,如果您不打算使用SQL Server,那么最好的选择就是研究可通过C#访问的No-SQL数据库,例如MongoDB。

If you're looking for something that serializes to a traditional RDBMS, I'm not aware of any open-source solutions offhand. 如果您正在寻找可以序列化到传统RDBMS的东西,那么我不会发现任何开源解决方案。 In C# there are ExpandoObjects, but I don't know whether that system includes database serialization/deserialization out of the box. 在C#中有ExpandoObjects,但我不知道该系统是否开箱即用地包括数据库序列化/反序列化。

There is Expando object beginning from the 4.0 version: dynamically expanding and shrinking object. 从4.0版本开始有Expando对象 :动态扩展和收缩对象。

If this is not what you are searching for, please clarify. 如果这不是您要查找的内容,请进行澄清。

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

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