문제

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.). 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. 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.

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. However, it does have its uses.

Variations on this theme are used in No-SQL databases ranging from Lotus Notes to Google BigTable. 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.

If you're looking for something that serializes to a traditional RDBMS, I'm not aware of any open-source solutions offhand. In C# there are ExpandoObjects, but I don't know whether that system includes database serialization/deserialization out of the box.

다른 팁

There is Expando object beginning from the 4.0 version: dynamically expanding and shrinking object.

If this is not what you are searching for, please clarify.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top