























拿 forum 做例子
forum继承自section section继承自ExtendedAttributes
ExtendedAttributes提供了属性动态扩展的功能
ExtendedAttributes中维护一个
NameValueCollection extendedAttributes = new NameValueCollection();
保存所有扩展属性
先来看下forum中定义的一个扩展属性
通过Get/Set ExtendedAttributes 在NameValueCollection中存取属性值
最终通过DataProvidor存到数据库中去,下面是SqlCommonDataProvider.CreateUpdateDeleteSection中的代码
GetSerializerData是 ExtendedAttributes定义的方法 用于将NameValueCollection中保存的属性序列化
Serializer.ConvertFromNameValueCollection(this.extendedAttributes,ref keys, ref values);
在cs中如果想给某个实体加一个属性, 只需要简单地在类中添加一个属性, 数据库的操作都根本不需要考虑。
当然动态扩展的属性不太容易实现检索。如果需要针对扩展属性进行检索的话,还得改数据表。
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。