c# - Fluent nHibernate - 映射字符串列表

标签 c# nhibernate fluent-nhibernate

我有一个这样的模型(简化)

public class Post
{
    public string ID { get; set; }    
    public string Title { get; set; }
    public string Body { get; set; }
    public string AuthorName { get; set; }

    public List<string> Attachments { get; set; }
}

在我的数据库中,我有一个 Post 表和一个 PostAttachment 表

帖子附件表有 2 列:

帖子编号 附件 key

(这个的基础是附件上传到amazon s3,所以AttachmentKey就是s3 key)

我想做的是将 AttachmentKey 映射到返回/插入的 Post 对象的列表...

我该怎么做?

最佳答案

@ben-hughes 你几乎明白了。

您不需要另一个映射。

HasMany(x => x.Attachments)
    .KeyColumn("PostID")
    .Table("PostAttachment").Element("AttachmentKey");

关于c# - Fluent nHibernate - 映射字符串列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3448331/

相关文章:

c# - 如何将数组拆分为一组 n 个元素?

c# - 将字节数组转换为带分隔符的字符串

nhibernate - 操作数类型冲突 : bigint is incompatible with time

.net - 无法获取StrongNameKeyPair的公钥

.net - NHibernate与EF 4.1+

c# - GMT 与 UTC 相同吗?

c# - 如何在 Visual Studio 中启动一个对象

c# - 将查询部分与 Lucene 和数据库 (MySQL) 中的部分相结合

c# - NHibernate Linq : how to use StartsWith on an integer type

.net - NHibernate - 如何映射到没有表的类(用于自定义 sql 查询)