FreeSql/FreeSql.DbContext/EfCoreFluentApi/EfCoreFluentApiExtensions.cs
2020-09-03 23:00:28 +08:00

38 lines
1.3 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using FreeSql;
using FreeSql.DataAnnotations;
using FreeSql.Extensions.EfCoreFluentApi;
using FreeSql.Internal.CommonProvider;
partial class FreeSqlDbContextExtensions
{
/// <summary>
/// EFCore 95% 相似的 FluentApi 扩展方法
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="codeFirst"></param>
/// <param name="modelBuilder"></param>
/// <returns></returns>
public static ICodeFirst Entity<T>(this ICodeFirst codeFirst, Action<EfCoreTableFluent<T>> modelBuilder)
{
var cf = codeFirst as CodeFirstProvider;
codeFirst.ConfigEntity<T>(tf => modelBuilder(new EfCoreTableFluent<T>(cf._orm, tf)));
return codeFirst;
}
/// <summary>
/// EFCore 95% 相似的 FluentApi 扩展方法
/// </summary>
/// <param name="codeFirst"></param>
/// <param name="entityType">实体类型</param>
/// <param name="modelBuilder"></param>
/// <returns></returns>
public static ICodeFirst Entity(this ICodeFirst codeFirst, Type entityType, Action<EfCoreTableFluent> modelBuilder)
{
var cf = codeFirst as CodeFirstProvider;
codeFirst.ConfigEntity(entityType, tf => modelBuilder(new EfCoreTableFluent(cf._orm, tf, entityType)));
return codeFirst;
}
}