我不知道如何将集合(评论)存储在单独的表中。
默认情况下,注释被序列化并作为列注释存储在 SomeClass 表中。
[{Id:0,CreateDate:2013-09-12T14:28:37.0456202+02:00,,SomeClassID:1,CommentText:"评论文本",}]
有没有办法将它保存在单独的表中?
public class SomeClass {
[AutoIncrement]
public int Id { get; set; }
public string Title { get; set; }
List<Comment> comments = new List<Comment>();
public List<Comment> Comments {
get { return comments; }
set { comments = value; }
}
}
public class Comment {
[AutoIncrement]
public int Id { get; set; }
[References(typeof(SomeClass))]
public int SomeClassID { get; set; }
[StringLength(4000)]
public string CommentText { get; set; }
}
最佳答案
我不认为 ORMLite 支持序列化到多个表。 1 个表 = 1 个类,因此注释将存储为 SomeClass 表中的 Blob 字段。
如果您需要将它们存储在单独的表中,则必须单独保存注释,并有一个外键引用回 SomeClass 表的 id。
关于ServiceStack ORMLite 如何不序列化列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18788595/