123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- using System;
- using System.Collections.Generic;
- using System.Text;
- using System.Linq;
- using Newtonsoft.Json;
- namespace FsDb.Test
- {
- class Program
- {
- static void Main(string[] args)
- {
- var db = new FsDbEngine(
- AppDomain.CurrentDomain.BaseDirectory
- .CombineLocalPath("data")
- );
- var colBook = db.GetCollection<Book>();
- var colTag = db.GetCollection<Tag>();
- var colBookTag = db.GetCollection<BookTag>();
- var book = new Book();
- var tag = new Tag();
- var booktag = new BookTag();
- colBook.Add(book);
- colTag.Add(tag);
- booktag.Book = book;
- booktag.Tag = tag;
- colBookTag.Add(booktag);
- colBook.Compress();
- colTag.Compress();
- colBookTag.Compress();
- }
- }
- class Book : FsDbEntityBase
- {
- public string Name { get; set; }
- public string Author { get; set; }
- public decimal Price { get; set; }
- public float Rank { get; set; }
- [JsonIgnore]
- public FsDbEntitySet<BookTag> BookTag { private set; get; }
- public Book()
- {
- BookTag = new FsDbEntitySet<BookTag>(
- this, p => p.BookID == this.ID
- , p => p.BookID = this.ID
- );
- }
- }
- class Tag : FsDbEntityBase
- {
- public int Name { get; set; }
- public float Rank { get; set; }
- [JsonIgnore]
- public FsDbEntitySet<BookTag> BookTag { private set; get; }
- public Tag()
- {
- BookTag = new FsDbEntitySet<BookTag>(
- this, p => p.TagID == this.ID
- , p => p.TagID = this.ID
- );
- }
- }
- class BookTag : FsDbEntityBase
- {
- public int BookID { get; set; }
- public int TagID { get; set; }
- public float Rank { get; set; }
- private FsDbEntityRef<Book> m_Book;
- private FsDbEntityRef<Tag> m_Tag;
- public BookTag()
- {
- m_Book = new FsDbEntityRef<Book>(
- this,
- p => p.ID == this.BookID
- , p => this.BookID = p.ID
- );
- m_Tag = new FsDbEntityRef<Tag>(
- this,
- p => p.ID == this.TagID
- , p => this.TagID = p.ID
- );
- }
- [JsonIgnore]
- public Book Book
- {
- get { return m_Book.Entity; }
- set { m_Book.Entity = value; }
- }
- [JsonIgnore]
- public Tag Tag
- {
- get { return m_Tag.Entity; }
- set { m_Tag.Entity = value; }
- }
- }
- }
|