Linq In Action 用于测试的数据

类图

代码

Author

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
using System;

namespace LinqInAction.LinqBooks.Common
{
    public class Author
    {
        public String FirstName { get; set; }
        public String LastName { get; set; }
        public String WebSite { get; set; }
    }
}

Book

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
using System;
using System.Collections.Generic;

namespace LinqInAction.LinqBooks.Common
{
    public class Book
    {
        public IEnumerable<Author> Authors { get; set; }
        public String Isbn { get; set; }
        public String Notes { get; set; }
        public Int32 PageCount { get; set; }
        public Decimal Price { get; set; }
        public DateTime PublicationDate { get; set; }
        public Publisher Publisher { get; set; }
        public IEnumerable<Review> Reviews { get; set; }
        public Subject Subject { get; set; }
        public String Summary { get; set; }
        public String Title { get; set; }

        public override String ToString()
        {
            return Title;
        }
    }
}

Publisher

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
using System;
using System.Drawing;

namespace LinqInAction.LinqBooks.Common
{
    public class Publisher
    {
        public String Name { get; set; }
        public Bitmap Logo { get; set; }
        public String WebSite { get; set; }

        public override string ToString()
        {
            return Name;
        }
    }
}

Review

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
using System;

namespace LinqInAction.LinqBooks.Common
{
    public class Review
    {
        public Book Book { get; set; }
        //public Guid User {get; set;}
        public User User { get; set; }
        public int Rating { get; set; }
        public String Comments { get; set; }
    }
}

Subject

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
using System;

namespace LinqInAction.LinqBooks.Common
{
    public class Subject
    {
        public String Description { get; set; }
        public String Name { get; set; }

        public override string ToString()
        {
            return Name;
        }
    }
}

User

1
2
3
4
5
6
7
8
9
using System;

namespace LinqInAction.LinqBooks.Common
{
    public class User
    {
        public String Name { get; set; }
    }
}

初始数据

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
using System;

namespace LinqInAction.LinqBooks.Common
{
    static public class SampleData
    {
        static public Publisher[] Publishers =
        {
      new Publisher {Name="FunBooks"},
      new Publisher {Name="Joe Publishing"},
      new Publisher {Name="I Publisher"}
    };

        static public Author[] Authors =
        {
      new Author {FirstName="Johnny", LastName="Good"},
      new Author {FirstName="Graziella", LastName="Simplegame"},
      new Author {FirstName="Octavio", LastName="Prince"},
      new Author {FirstName="Jeremy", LastName="Legrand"}
    };

        static public Subject[] Subjects =
        {
      new Subject {Name="Software development"},
      new Subject {Name="Novel"},
      new Subject {Name="Science fiction"}
    };

        static public Book[] Books =
        {
      new Book {
        Title="Funny Stories",
        Publisher=Publishers[0],
        Authors=new[]{Authors[0], Authors[1]},
        PageCount=101,
        Price=25.55M,
        PublicationDate=new DateTime(2004, 11, 10),
        Isbn="0-000-77777-2",
        Subject=Subjects[0]
      },
      new Book {
        Title="LINQ rules",
        Publisher=Publishers[1],
        Authors=new[]{Authors[2]},
        PageCount=300,
        Price=12M,
        PublicationDate=new DateTime(2007, 9, 2),
        Isbn="0-111-77777-2",
        Subject=Subjects[0]
      },
      new Book {
        Title="C# on Rails",
        Publisher=Publishers[1],
        Authors=new[]{Authors[2]},
        PageCount=256,
        Price=35.5M,
        PublicationDate=new DateTime(2007, 4, 1),
        Isbn="0-222-77777-2",
        Subject=Subjects[0]
      },
      new Book {
        Title="All your base are belong to us",
        Publisher=Publishers[1],
        Authors=new[]{Authors[3]},
        PageCount=1205,
        Price=35.5M,
        PublicationDate=new DateTime(2006, 5, 5),
        Isbn="0-333-77777-2",
        Subject=Subjects[2]
      },
      new Book {
        Title="Bonjour mon Amour",
        Publisher=Publishers[0],
        Authors=new[]{Authors[1], Authors[0]},
        PageCount=50,
        Price=29M,
        PublicationDate=new DateTime(1973, 2, 18),
        Isbn="2-444-77777-2",
        Subject=Subjects[1]
      }
    };
    }
}

参考:

Fabrice Marguerie,Steve Eichert,Jim Wooley.LINQ in Action.Manning Publications,2008-2-14. http://linqinaction.net/