@@ -66,38 +66,35 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
66
66
/// </summary>
67
67
public static class FakeData
68
68
{
69
- public static Faker < Blog > BlogFaker ;
70
- public static Faker < Post > PostFaker ;
71
-
72
69
public static List < Blog > Blogs = new List < Blog > ( ) ;
73
70
public static List < Post > Posts = new List < Post > ( ) ;
74
71
75
72
public static void Init ( int count )
76
73
{
77
74
var postId = 1 ;
78
- PostFaker = new Faker < Post > ( )
75
+ var postFaker = new Faker < Post > ( )
79
76
. RuleFor ( p => p . PostId , _ => postId ++ )
80
77
. RuleFor ( p => p . Title , f => f . Hacker . Phrase ( ) )
81
78
. RuleFor ( p => p . Content , f => f . Lorem . Sentence ( ) ) ;
82
79
83
80
var blogId = 1 ;
84
- BlogFaker = new Faker < Blog > ( )
81
+ var blogFaker = new Faker < Blog > ( )
85
82
. RuleFor ( b => b . BlogId , _ => blogId ++ )
86
83
. RuleFor ( b => b . Url , f => f . Internet . Url ( ) )
87
84
. RuleFor ( b => b . Posts , ( f , b ) =>
88
85
{
89
- var posts = PostFaker . GenerateBetween ( 3 , 5 ) ;
90
- FakeData . Posts . AddRange ( posts ) ;
86
+ postFaker . RuleFor ( p => p . BlogId , fp => b . BlogId ) ;
91
87
92
- foreach ( var post in posts )
93
- {
94
- post . BlogId = b . BlogId ;
95
- }
88
+ var posts = postFaker . GenerateBetween ( 3 , 5 ) ;
89
+
90
+ FakeData . Posts . AddRange ( posts ) ;
96
91
97
92
return null ; // Blog.Posts is a getter only. The return value has no impact.
98
93
} ) ;
99
94
100
- Blogs = BlogFaker . Generate ( count ) ;
95
+ var blogs = blogFaker . Generate ( count ) ;
96
+
97
+ FakeData . Blogs . AddRange ( blogs ) ;
101
98
}
102
99
}
103
100
0 commit comments