mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-06-18 20:08:15 +08:00
- 增加 EfCoreFluentApi 扩展包,接近 efcore fluentApi 的使用习惯;#4
- 增加 ColumnAttribute 属性 InsertValueSql,插入数据的时候指定用 sql 值;
This commit is contained in:
@ -0,0 +1,37 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq.Expressions;
|
||||
using FreeSql.DataAnnotations;
|
||||
|
||||
namespace FreeSql.Extensions.EfCoreFluentApi
|
||||
{
|
||||
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)
|
||||
{
|
||||
codeFirst.ConfigEntity<T>(tf => modelBuilder(new EfCoreTableFluent<T>(tf)));
|
||||
return codeFirst;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user