简体   繁体   中英

ServiceStack ORMLite how to not serialize list

I don't know how to store collection (Comments) in separate table. By default comments are serialized and stored in SomeClass table as column Comments.

[{Id:0,CreateDate:2013-09-12T14:28:37.0456202+02:00,,SomeClassID:1,CommentText:"coment text",}]

Is there any way to save it in separate tables?

    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; }

}

I don't think ORMLite supports serializing to multiple tables. 1 table = 1 class so the comments will be stored as a Blob field in the SomeClass table.

If you need to store them in separate tables you will have to save the comments separately and have a foreign key reference back to the id of the SomeClass table.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM