惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

V
Visual Studio Blog
Microsoft Azure Blog
Microsoft Azure Blog
WordPress大学
WordPress大学
小众软件
小众软件
Last Week in AI
Last Week in AI
月光博客
月光博客
博客园 - 聂微东
Recent Announcements
Recent Announcements
A
About on SuperTechFans
博客园 - 三生石上(FineUI控件)
V
V2EX
阮一峰的网络日志
阮一峰的网络日志
博客园 - Franky
云风的 BLOG
云风的 BLOG
量子位
N
Netflix TechBlog - Medium
Hugging Face - Blog
Hugging Face - Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
J
Java Code Geeks
博客园 - 司徒正美
S
SegmentFault 最新的问题
有赞技术团队
有赞技术团队
Google DeepMind News
Google DeepMind News
宝玉的分享
宝玉的分享

博客园 - huangyi

垃圾回收 郁闷 MyConsole 白做了 Winform程序中打开控制台 心目中软件开发的未来 把新闻系统转到CommunityServer下的几点体会 css学习笔记 Float css学习笔记 Position CommunityServer下的新闻系统 qq 被人骗走了啊 狗日的 2千多个小时啊 Enterprise Library CommunityServer如何管理Url CommuntyServer架构分析 web2.0 与 未来网 论坛 博客 相册 留言本 开发计划 微软技术一个共同点 学习avalon的第一个小程序 献丑了 与delphi有关 看到Agent Oriented Programmig感想 Introduce Longhorn to developers(The Longhorn Application Model)[翻译]
CommunityServer如何实现属性的动态扩展
huangyi · 2005-08-09 · via 博客园 - huangyi

拿 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中如果想给某个实体加一个属性,  只需要简单地在类中添加一个属性,  数据库的操作都根本不需要考虑。

当然动态扩展的属性不太容易实现检索。如果需要针对扩展属性进行检索的话,还得改数据表。