File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed
Extensions/FreeSql.Extensions.EfCoreFluentApi Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -29,6 +29,34 @@ static void Test()
2929 // 多对多
3030 eb .HasMany (a => a .Tags ).WithMany (a => a .Songs , typeof (Song_tag ));
3131 });
32+
33+ cf .Entity <SongType >(eb =>
34+ {
35+ eb .HasMany (a => a .Songs ).WithOne (a => a .Type ).HasForeignKey (a => a .TypeId );
36+
37+ eb .HasData (new []
38+ {
39+ new SongType
40+ {
41+ Id = 1 ,
42+ Name = " 流行" ,
43+ Songs = new List <Song >(new []
44+ {
45+ new Song { Title = " 真的爱你" },
46+ new Song { Title = " 爱你一万年" },
47+ })
48+ },
49+ new SongType
50+ {
51+ Id = 2 ,
52+ Name = " 乡村" ,
53+ Songs = new List <Song >(new []
54+ {
55+ new Song { Title = " 乡里乡亲" },
56+ })
57+ },
58+ });
59+ });
3260}
3361
3462public class SongType
@@ -41,6 +69,7 @@ public class SongType
4169
4270public class Song
4371{
72+ [Column (IsIdentity = true )]
4473 public int Id { get ; set ; }
4574 public string Title { get ; set ; }
4675 public string Url { get ; set ; }
You can’t perform that action at this time.
0 commit comments