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

推荐订阅源

美团技术团队
D
DataBreaches.Net
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
D
Docker
N
Netflix TechBlog - Medium
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
C
Check Point Blog
腾讯CDC
Stack Overflow Blog
Stack Overflow Blog
V
Visual Studio Blog
IT之家
IT之家
月光博客
月光博客
U
Unit 42
K
Kaspersky official blog
T
Threatpost
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
GbyAI
GbyAI
P
Proofpoint News Feed
Last Week in AI
Last Week in AI
云风的 BLOG
云风的 BLOG
酷 壳 – CoolShell
酷 壳 – CoolShell
I
InfoQ
Engineering at Meta
Engineering at Meta
Recorded Future
Recorded Future
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
S
Security @ Cisco Blogs
MyScale Blog
MyScale Blog
大猫的无限游戏
大猫的无限游戏
Security Archives - TechRepublic
Security Archives - TechRepublic
Webroot Blog
Webroot Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Hacker News - Newest:
Hacker News - Newest: "LLM"
S
Schneier on Security
S
Secure Thoughts
The Register - Security
The Register - Security
B
Blog RSS Feed
The Last Watchdog
The Last Watchdog
P
Palo Alto Networks Blog
爱范儿
爱范儿
B
Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
N
News and Events Feed by Topic
阮一峰的网络日志
阮一峰的网络日志
L
LINUX DO - 热门话题
C
Cisco Blogs
Spread Privacy
Spread Privacy
F
Full Disclosure
博客园 - 聂微东
T
The Blog of Author Tim Ferriss

博客园 - 红色石头

删除表中多余的重复记录 c#里正则表达式的例子 水晶报表中动态显示图片 Javascript中定义类 - 红色石头 - 博客园 castle实例分析(一) url传递中文的方法 - 红色石头 - 博客园 水晶报表中设定每页显示的行数 服务器控件Table的使用 asp.net2.0中关于ASP.NET 网站管理工具无法连接sql server 数据库的处理 转载一张有趣的图片 动态添加用户控件和服务器控件(二) 动态添加用户控件或服务器控件(一) XML格式的字符串和DataSet之间的相互转换 SQL Server2005关于web服务的配置 在VS2005中用C#写存储过程 控制模版列的文本框在编辑时只读 控制模版列的文本框只能输入数字并且禁止粘贴 利用.net正则表达式化繁为简的一个实例 利用SqlServer2005的新增函数实现更高效的分页存储过程
castle实例分析(二)
红色石头 · 2007-05-30 · via 博客园 - 红色石头

HasMany--表示一对多的关系

Posts 的blogid是blogs表的外键,可以在blog类中设置HasMany属性,使blog类有一系列的Posts

using Castle.ActiveRecord;
 [ActiveRecord("blogs")]
public class Blog : ActiveRecordBase
{
    private int id;
    private string name;
    private IList posts = new ArrayList();
    [PrimaryKey]
    public int Id
    {
        get { return id; }
        set { id = value; }
    }
    [Property]
    public string Name
    {
        get { return name; }
        set { name = value; }
    }
    [HasMany(typeof(Post), Table="Posts", ColumnKey="blogid"),
 Inverse=true, Cascade=ManyRelationCascadeEnum.AllDeleteOrphan)]
    public IList Posts
    {
        get { return posts; }
        set { posts = value; }
    }
}
注意:如果另一边有关联的类(Post类)有BelongsTo关联blog类,可以省略Table和ColumnKey 属性

使用示例:
Blog blog = new Blog();
blog.Name = "hammett's blog";
blog.Create();
Post post = new Post();
post.Title = "First post";
post.Contents = "Hello world";
post.Create();
blog.Posts.Add(post);
blog.Update();