From:一条被猫抛弃的他乡流浪狗!

SimpleData-简单了解

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Simple.Data;

namespace SimpleDataStudy
{
    class Program
    {
        static void Main(string[] args)
        {
            var db = Database.OpenConnection("Server=.;Database=Dapper;Uid=sa;Pwd=******;");
            Book book = db.Book.FindById(14);
            Console.WriteLine(book);

            Book bookAdd=new Book(){Name = "Java"};
            db.Book.Insert(bookAdd);

            Book bookUpdate=new Book(){Id=14,Name = "update"};
            db.Book.Update(bookUpdate);

            //db.Book.DeleteById(6);

            Console.WriteLine("ok");
            Console.ReadKey();
        }
    }

    public class Book
    {
        public Book()
        {
            Reviews = new List<BookReview>();
        }
        public int Id { get; set; }
        public string Name { get; set; }
        public virtual List<BookReview> Reviews { get; set; }
        public override string ToString()
        {
            return string.Format("[{0}]------《{1}》", Id, Name);
        }
    }

    public class BookReview
    {
        public int Id { get; set; }
        public int BookId { get; set; }
        public virtual string Content { get; set; }
        public virtual Book AssoicationWithBook { get; set; }
        public override string ToString()
        {
            return string.Format("{0})--[{1}]\t\"{3}\"", Id, BookId, Content);
        }
    }
}

  

posted @ 2016-06-02 17:21  ICE_Inspire  阅读(198)  评论(0编辑  收藏  举报