3
3
using Craftsman . Helpers ;
4
4
using Craftsman . Models ;
5
5
using System ;
6
+ using Enums ;
6
7
7
8
public static class SeederFunctions
8
9
{
9
10
public static string GetEntitySeederFileText ( string classNamespace , Entity entity , string dbContextName , string solutionDirectory , string projectBaseName )
10
11
{
11
12
var entitiesClassPath = ClassPathHelper . EntityClassPath ( solutionDirectory , "" , entity . Plural , projectBaseName ) ;
13
+ var dtoClassPath = ClassPathHelper . DtoClassPath ( solutionDirectory , "" , entity . Name , projectBaseName ) ;
12
14
var dbContextClassPath = ClassPathHelper . DbContextClassPath ( solutionDirectory , "" , projectBaseName ) ;
15
+ var entityForCreationDto = $ "Fake{ Utilities . GetDtoName ( entity . Name , Dto . Creation ) } ";
13
16
if ( dbContextName is null )
14
17
{
15
18
throw new ArgumentNullException ( nameof ( dbContextName ) ) ;
@@ -19,6 +22,7 @@ public static string GetEntitySeederFileText(string classNamespace, Entity entit
19
22
20
23
using AutoBogus;
21
24
using { entitiesClassPath . ClassNamespace } ;
25
+ using { dtoClassPath . ClassNamespace } ;
22
26
using { dbContextClassPath . ClassNamespace } ;
23
27
using System.Linq;
24
28
@@ -28,9 +32,9 @@ public static class {Utilities.GetSeederName(entity)}
28
32
{{
29
33
if (!context.{ entity . Plural } .Any())
30
34
{{
31
- context.{ entity . Plural } .Add(new AutoFaker<{ entity . Name } >());
32
- context.{ entity . Plural } .Add(new AutoFaker<{ entity . Name } >());
33
- context.{ entity . Plural } .Add(new AutoFaker<{ entity . Name } >());
35
+ context.{ entity . Plural } .Add({ entity . Name } .Create( new AutoFaker<{ entityForCreationDto } >() ));
36
+ context.{ entity . Plural } .Add({ entity . Name } .Create( new AutoFaker<{ entityForCreationDto } >() ));
37
+ context.{ entity . Plural } .Add({ entity . Name } .Create( new AutoFaker<{ entityForCreationDto } >() ));
34
38
35
39
context.SaveChanges();
36
40
}}
0 commit comments