mirror of
				https://github.com/nsnail/FreeSql.git
				synced 2025-11-04 09:15:27 +08:00 
			
		
		
		
	update readme
This commit is contained in:
		@@ -8,30 +8,75 @@ namespace FreeSql.Extensions.EfCoreFluentApi
 | 
				
			|||||||
    public static class ICodeFirstExtensions
 | 
					    public static class ICodeFirstExtensions
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        static void Test()
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            ICodeFirst cf = null;
 | 
					 | 
				
			||||||
            cf.Entity<TestInfo>(eb =>
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                eb.Property(b => b.Name).HashColumnType("varchar(50)");
 | 
					 | 
				
			||||||
                eb.Property(b => b.FullName).HashColumnType("varchar(60)");
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                eb.HasKey(a => a.Id).HasKey(a => new { a.Id, a.Name });
 | 
					 | 
				
			||||||
                eb.HasIndex(a => a.Name).IsUnique().HasName("idx_xxx11");
 | 
					 | 
				
			||||||
            });
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        class TestInfo
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            public int Id { get; set; }
 | 
					 | 
				
			||||||
            public string Name { get; set; }
 | 
					 | 
				
			||||||
            public string FullName { get; set; }
 | 
					 | 
				
			||||||
            public int DefaultValue { get; set; }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        public static ICodeFirst Entity<T>(this ICodeFirst codeFirst, Action<EfCoreTableFluent<T>> modelBuilder)
 | 
					        public static ICodeFirst Entity<T>(this ICodeFirst codeFirst, Action<EfCoreTableFluent<T>> modelBuilder)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            codeFirst.ConfigEntity<T>(tf => modelBuilder(new EfCoreTableFluent<T>(tf)));
 | 
					            codeFirst.ConfigEntity<T>(tf => modelBuilder(new EfCoreTableFluent<T>(tf)));
 | 
				
			||||||
            return codeFirst;
 | 
					            return codeFirst;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        static void Test()
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            ICodeFirst cf = null;
 | 
				
			||||||
 | 
					            cf.Entity<Song>(eb =>
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                eb.ToTable("tb_song");
 | 
				
			||||||
 | 
					                eb.Ignore(a => a.Field1);
 | 
				
			||||||
 | 
					                eb.Property(a => a.Title).HashColumnType("varchar(50)").IsRequired();
 | 
				
			||||||
 | 
					                eb.Property(a => a.Url).HasMaxLength(100);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                eb.Property(a => a.RowVersion).IsRowVersion();
 | 
				
			||||||
 | 
					                eb.Property(a => a.CreateTime).HasDefaultValueSql("getdate()");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                eb.HasKey(a => a.Id);
 | 
				
			||||||
 | 
					                eb.HasIndex(a => a.Title).IsUnique().HasName("idx_xxx11");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                //一对多、多对一
 | 
				
			||||||
 | 
					                eb.HasOne(a => a.Type).HasForeignKey(a => a.TypeId).WithMany(a => a.Songs);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                //多对多
 | 
				
			||||||
 | 
					                eb.HasMany(a => a.Tags).WithMany(a => a.Songs, typeof(Song_tag));
 | 
				
			||||||
 | 
					            });
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        public class SongType
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            public int Id { get; set; }
 | 
				
			||||||
 | 
					            public string Name { get; set; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            public List<Song> Songs { get; set; }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        public class Song
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            public int Id { get; set; }
 | 
				
			||||||
 | 
					            public string Title { get; set; }
 | 
				
			||||||
 | 
					            public string Url { get; set; }
 | 
				
			||||||
 | 
					            public DateTime CreateTime { get; set; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            public int TypeId { get; set; }
 | 
				
			||||||
 | 
					            public SongType Type { get; set; }
 | 
				
			||||||
 | 
					            public List<Tag> Tags { get; set; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            public int Field1 { get; set; }
 | 
				
			||||||
 | 
					            public long RowVersion { get; set; }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        public class Song_tag
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            public int Song_id { get; set; }
 | 
				
			||||||
 | 
					            public Song Song { get; set; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            public int Tag_id { get; set; }
 | 
				
			||||||
 | 
					            public Tag Tag { get; set; }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        public class Tag
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            [Column(IsIdentity = true)]
 | 
				
			||||||
 | 
					            public int Id { get; set; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            public string Name { get; set; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            public List<Song> Songs { get; set; }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										70
									
								
								Extensions/FreeSql.Extensions.EfCoreFluentApi/readme.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										70
									
								
								Extensions/FreeSql.Extensions.EfCoreFluentApi/readme.md
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,70 @@
 | 
				
			|||||||
 | 
					这个 FreeSql 扩展包,实现与 EfCore FluentApi 95% 相似的使用习惯;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					## 以假乱真
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					```csharp
 | 
				
			||||||
 | 
					static void Test()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    ICodeFirst cf = null;
 | 
				
			||||||
 | 
					    cf.Entity<Song>(eb =>
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        eb.ToTable("tb_song");
 | 
				
			||||||
 | 
					        eb.Ignore(a => a.Field1);
 | 
				
			||||||
 | 
					        eb.Property(a => a.Title).HashColumnType("varchar(50)").IsRequired();
 | 
				
			||||||
 | 
					        eb.Property(a => a.Url).HasMaxLength(100);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        eb.Property(a => a.RowVersion).IsRowVersion();
 | 
				
			||||||
 | 
					        eb.Property(a => a.CreateTime).HasDefaultValueSql("getdate()");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        eb.HasKey(a => a.Id);
 | 
				
			||||||
 | 
					        eb.HasIndex(a => a.Title).IsUnique().HasName("idx_xxx11");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        //一对多、多对一
 | 
				
			||||||
 | 
					        eb.HasOne(a => a.Type).HasForeignKey(a => a.TypeId).WithMany(a => a.Songs);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        //多对多
 | 
				
			||||||
 | 
					        eb.HasMany(a => a.Tags).WithMany(a => a.Songs, typeof(Song_tag));
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public class SongType
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    public int Id { get; set; }
 | 
				
			||||||
 | 
					    public string Name { get; set; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public List<Song> Songs { get; set; }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public class Song
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    public int Id { get; set; }
 | 
				
			||||||
 | 
					    public string Title { get; set; }
 | 
				
			||||||
 | 
					    public string Url { get; set; }
 | 
				
			||||||
 | 
					    public DateTime CreateTime { get; set; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public int TypeId { get; set; }
 | 
				
			||||||
 | 
					    public SongType Type { get; set; }
 | 
				
			||||||
 | 
					    public List<Tag> Tags { get; set; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public int Field1 { get; set; }
 | 
				
			||||||
 | 
					    public long RowVersion { get; set; }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					public class Song_tag
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    public int Song_id { get; set; }
 | 
				
			||||||
 | 
					    public Song Song { get; set; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public int Tag_id { get; set; }
 | 
				
			||||||
 | 
					    public Tag Tag { get; set; }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public class Tag
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    [Column(IsIdentity = true)]
 | 
				
			||||||
 | 
					    public int Id { get; set; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public string Name { get; set; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public List<Song> Songs { get; set; }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
		Reference in New Issue
	
	Block a user