Interface ICodeFirst
Namespace: FreeSql
Assembly: FreeSql.dll
Syntax
public interface ICodeFirst
Properties
| Improve this Doc View SourceIsAutoSyncStructure
【开发环境必备】自动同步实体结构到数据库,程序运行中检查实体表是否存在,然后创建或修改
Declaration
bool IsAutoSyncStructure { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
IsConfigEntityFromDbFirst
将数据库的主键、自增、索引设置导入,适用 DbFirst 模式,无须在实体类型上设置 [Column(IsPrimary)] 或者 ConfigEntity。此功能目前可用于 mysql/sqlserver/postgresql/oracle。
本功能会影响 IFreeSql 首次访问的速度。
若使用 CodeFirst 创建索引后,又直接在数据库上建了索引,若无本功能下一次 CodeFirst 迁移时数据库上创建的索引将被删除
Declaration
bool IsConfigEntityFromDbFirst { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
IsGenerateCommandParameterWithLambda
是否生成命令参数化执行,针对 lambda 表达式解析
注意:常量不会参数化,变量才会做参数化
var id = 100; fsql.Select<T>().Where(a => a.id == id) 会参数化
fsql.Select<T>().Where(a => a.id == 100) 不会参数化
Declaration
bool IsGenerateCommandParameterWithLambda { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
IsLazyLoading
延时加载导航属性对象,导航属性需要声明 virtual
Declaration
bool IsLazyLoading { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
IsNoneCommandParameter
不使用命令参数化执行,针对 Insert/Update
Declaration
bool IsNoneCommandParameter { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
IsSyncStructureToLower
转小写同步结构,适用 PostgreSQL
Declaration
bool IsSyncStructureToLower { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
IsSyncStructureToUpper
转大写同步结构,适用 Oracle/达梦/人大金仓
Declaration
bool IsSyncStructureToUpper { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
Methods
| Improve this Doc View SourceConfigEntity(Type, Action<TableFluent>)
FreeSql FluentApi 配置实体,方法名与特性相同
Declaration
ICodeFirst ConfigEntity(Type type, Action<TableFluent> entity)
Parameters
Type | Name | Description |
---|---|---|
System.Type | type | |
System.Action<TableFluent> | entity |
Returns
Type | Description |
---|---|
ICodeFirst |
ConfigEntity<T>(Action<TableFluent<T>>)
FreeSql FluentApi 配置实体,方法名与特性相同
Declaration
ICodeFirst ConfigEntity<T>(Action<TableFluent<T>> entity)
Parameters
Type | Name | Description |
---|---|---|
System.Action<TableFluent<T>> | entity |
Returns
Type | Description |
---|---|
ICodeFirst |
Type Parameters
Name | Description |
---|---|
T |
GetComparisonDDLStatements(Type, String)
将实体类型与数据库对比,返回DDL语句(指定表名)
Declaration
string GetComparisonDDLStatements(Type entityType, string tableName)
Parameters
Type | Name | Description |
---|---|---|
System.Type | entityType | 实体类型 |
System.String | tableName | 指定表名对比 |
Returns
Type | Description |
---|---|
System.String |
GetComparisonDDLStatements(Type[])
将实体类型集合与数据库对比,返回DDL语句
Declaration
string GetComparisonDDLStatements(params Type[] entityTypes)
Parameters
Type | Name | Description |
---|---|---|
System.Type[] | entityTypes | 实体类型 |
Returns
Type | Description |
---|---|
System.String |
GetComparisonDDLStatements<TEntity>()
将实体类型与数据库对比,返回DDL语句
Declaration
string GetComparisonDDLStatements<TEntity>()
Returns
Type | Description |
---|---|
System.String |
Type Parameters
Name | Description |
---|---|
TEntity |
GetConfigEntity(Type)
获取 FreeSql FluentApi 配置实体的元数据
Declaration
TableAttribute GetConfigEntity(Type type)
Parameters
Type | Name | Description |
---|---|---|
System.Type | type |
Returns
Type | Description |
---|---|
TableAttribute | 未使用ConfigEntity配置时,返回null |
GetDbInfo(Type)
根据 System.Type 获取数据库信息
Declaration
DbInfoResult GetDbInfo(Type type)
Parameters
Type | Name | Description |
---|---|---|
System.Type | type |
Returns
Type | Description |
---|---|
DbInfoResult |
GetTableByEntity(Type)
获取实体类核心配置
Declaration
TableInfo GetTableByEntity(Type type)
Parameters
Type | Name | Description |
---|---|---|
System.Type | type |
Returns
Type | Description |
---|---|
TableInfo |
SyncStructure(Type, String, Boolean)
同步实体类型到数据库(指定表名)
注意:生产环境中谨慎使用
Declaration
void SyncStructure(Type entityType, string tableName, bool isForceSync = false)
Parameters
Type | Name | Description |
---|---|---|
System.Type | entityType | 实体类型 |
System.String | tableName | 指定表名对比 |
System.Boolean | isForceSync | 强制同步结构,无视缓存每次都同步 |
SyncStructure(Type[])
同步实体类型集合到数据库
注意:生产环境中谨慎使用
Declaration
void SyncStructure(params Type[] entityTypes)
Parameters
Type | Name | Description |
---|---|---|
System.Type[] | entityTypes |
SyncStructure<TEntity>()
同步实体类型到数据库
注意:生产环境中谨慎使用
Declaration
void SyncStructure<TEntity>()
Type Parameters
Name | Description |
---|---|
TEntity |