[EF] Table Per Type(TPT)

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://david.blog.csdn.net/article/details/90511799

Table per Type(TPT,每一种类型一张表)通过类型基础建立数据实体对应关联数据表的外键,与TPH不同德地方在于,每一个数据类型均对应到独立的数据表,数据表彼此形成关联的外键就形成彼此间的集成关系。

namespace TPTDemo.Model
{
    [Table("Product")]
    public class Product
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public int Price { get; set; }
    }
    [Table("Book")]
    public class Book : Product
    {
        public string Title { get; set; }
        public string ISBN { get; set; }
        public string Author { get; set; }
        public int Pages { get; set; }
    }
    [Table("Magazine")]
    public class Magazine : Product
    {
        public int Year { get; set; }
        public int Month { get; set; }
        public string ISSN { get; set; }
        public int MPages { get; set; }
    }
}

表之间关系:
在这里插入图片描述
在这里插入图片描述
主程序:


            using (var model = new KTStoreModel())
            {
                        
                var products = model.Products;
                Console.WriteLine("\nBook\n{0}", new String('-', 36));
                foreach (var book in products.OfType<Book>())
                {
                    Console.WriteLine("{0} 页数:{1} ISBN:{2} 作者:{3}",
                        book.Title,
                        book.Pages,
                        book.ISBN,
                        book.Author);
                }
                Console.WriteLine("\nMagazine\n{0}", new String('-', 36));
                foreach (var magazine in products.OfType<Magazine>())
                {
                    Console.WriteLine("{0} 页数:{1} ISSN:{2} 年份:{3} 月份:{4}",
                        magazine.Name,
                        magazine.MPages,
                        magazine.ISSN,
                        magazine.Year,
                        magazine.Month);
                }
                int c = model.Products.Count();
                Console.WriteLine("\n总计数据项数:{0}", c);


                /*
                while (true)
                {
                    Console.Write("\n1.图书 2.杂志 ");
                    int i = int.Parse(Console.ReadLine());

                    if (i == 1)
                    {
                        Console.Write("\n按序输入 书名,价格,页数,ISBN,作者:");
                        string info = Console.ReadLine();
                        string[] infos = info.Split(',');

                        Product book = new Book
                        {
                            Name = "图书-" + infos[0],
                            Title = infos[0],
                            Price = int.Parse(infos[1]),
                            Pages = int.Parse(infos[2]),
                            ISBN = infos[3],
                            Author = infos[4]
                        };
                        model.Products.Add(book);
                        model.SaveChanges();
                    }
                    else if (i == 2)
                    {
                        Console.Write("\n按序输入 杂志名称,价格,页数,ISSN,年份,月:");
                        string info = Console.ReadLine();
                        string[] infos = info.Split(',');

                        Product magazine = new Magazine
                        {
                            Name = "杂志-" + infos[0],
                            Price = int.Parse(infos[1]),
                            MPages = int.Parse(infos[2]),
                            ISSN = infos[3],
                            Year = int.Parse(infos[4]),
                            Month = int.Parse(infos[5])
                        };
                        model.Products.Add(magazine);
                        model.SaveChanges();
                    }
                    else
                    {
                        break;
                    }
                }
                */
                Console.ReadLine();
            }

在这里插入图片描述

展开阅读全文

per 请进

03-11

---sp1补丁rnrnselect * into view_T1 from (select id=1 union all select id=3 union all select id=2)xrnrnrnrncreate view view1rnasrnselect top 100 percent id from view_T1rnorder by idrnrnrnselect id from view1rnrnidrn-----------rn1rn3rn2rnrn(3 行受影响)rnrn---并没有受影响rnrn--sp2补丁rnrnrnselect * into view_T1 from (select id=1 union all select id=3 union all select id=2)xrnrnrnrncreate view view1rnasrnselect top 100 percent id from view_T1rnorder by idrnrnrnselect id from view1rnrnidrn-----------rn1rn3rn2rnrn(3 行受影响)rnrn也没有受影响rnrn---出处rn1sql ansi 视图的定义rnrn2tsql inside 2005 程序设计rnpage:rn184 视图rn创建排序视图本身的企图就是错误的,因为视图表示一个表rn而表是不会对行排序的。rn众所周知 在sql2000中追求 排序视图的开发人员会利用貌似系统漏洞这一技巧rn利用找个漏洞可以创建一个非常可笑的视图 比如 top 100 percentrn视图中的 order by 子句意味着什么?他的意义不是很明确 因为 top选项 不是ansi标准rn但你如果从集合的角度考虑一下 就会认为 order by 子句没有什么意义了。rn因为你已经筛选了表达式(filter expression)的行 查询视图 sqlserver 不保证输出的顺序rn。。。。。。。。rnrnrn难道微软准备出可以排序的视图的补丁?rn没打sp3rnps 关于重建索引 非聚是因为指针指向不同 先新建非聚 后删除原来的非聚 rn而不是简单的把 区号 页号 行号 换成 聚的键值.rn那说以前讨论不对 是那个非聚优于聚集。不是索引结构。rn所以在查询一个有聚集和非据表时候 会优先查询 非据 然后指向键值rn比直接差聚集 少读取2层数据叶。 rnrn哪里不对请指教。 顺便指出出处rn 论坛

org.hibernate.MappingException: Could not determine type for: string , at table

11-18

Books.javarn[code=Java]rnpackage com.ssh.books.model;rnrnimport java.sql.Date;rnrnpublic class Books rn private String bookId;rn private String name;rn private String author;rn private String publish;rn private Date date;rn private String isbn;rn private int page;rn private String bookPrice;rn private String content;rn rn rnrn public String getBookId() rn return bookId;rn rn public void setBookId(String bookId) rn this.bookId = bookId;rn rn public String getName() rn return name;rn rn public void setName(String name) rn this.name = name;rn rn public String getAuthor() rn return author;rn rn public void setAuthor(String author) rn this.author = author;rn rn public String getPublish() rn return publish;rn rn public void setPublish(String publish) rn this.publish = publish;rn rn public Date getDate() rn return date;rn rn public void setDate(Date date) rn this.date = date;rn rn public String getIsbn() rn return isbn;rn rn public void setIsbn(String isbn) rn this.isbn = isbn;rn rn public int getPage() rn return page;rn rn public void setPage(int page) rn this.page = page;rn rn public String getBookPrice() rn return bookPrice;rn rn public void setBookPrice(String bookPrice) rn this.bookPrice = bookPrice;rn rn public String getContent() rn return content;rn rn public void setContent(String content) rn this.content = content;rn rnrnrnrnrnBooks.hbm.xmlrn[/code]rnrn[code=XML]rnrnrnrnrnrnrn rnrn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rnrnrnrnrnrnrn[/code]rnrnrn[color=#FF0000]rnCaused by: org.hibernate.MappingException: Could not determine type for: string , at table: books, for columns: [org.hibernate.mapping.Column(book_id)]rn[/color] 论坛

没有更多推荐了,返回首页