huangyiiiiii

此blog不再更新,大家都去我的新家吧http://codeplayer.blogbus.com

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
拿 forum  做例子
forum继承自section   section继承自ExtendedAttributes
ExtendedAttributes提供了属性动态扩展的功能
ExtendedAttributes中维护一个
NameValueCollection extendedAttributes = new NameValueCollection();
保存所有扩展属性
先来看下forum中定义的一个扩展属性
public string ForumLogo
        
{
            
get{return GetExtendedAttribute("ForumLogo");}
            
set{SetExtendedAttribute("ForumLogo", value);}
        }
通过Get/Set ExtendedAttributes  在NameValueCollection中存取属性值 
最终通过DataProvidor存到数据库中去,下面是SqlCommonDataProvider.CreateUpdateDeleteSection中的代码
SerializerData data = section.GetSerializerData();
                    myCommand.Parameters.Add(
"@PropertyNames", SqlDbType.NText).Value = data.Keys;
                    myCommand.Parameters.Add(
"@PropertyValues", SqlDbType.NText).Value = data.Values;
GetSerializerData是 ExtendedAttributes定义的方法  用于将NameValueCollection中保存的属性序列化
Serializer.ConvertFromNameValueCollection(this.extendedAttributes,ref keys, ref values);


在cs中如果想给某个实体加一个属性,  只需要简单地在类中添加一个属性,  数据库的操作都根本不需要考虑。

当然动态扩展的属性不太容易实现检索。如果需要针对扩展属性进行检索的话,还得改数据表。
posted on 2005-08-09 11:15  huangyi  阅读(722)  评论(0编辑  收藏  举报