FluentMigrator 中的 NotMapped 和 AsNoTracking 等效项
NotMapped and AsNoTracking equivalent in FluentMigrator
Fluent Migrator .Net ORM 中 NotMapped 属性和 AsNoTracking 方法的等效项是什么?我正在将我使用 EF6 作为 ORM 的项目之一迁移到 Fluent Migrator。我 google 对此有很多了解,但找不到任何有用的信息。
FluentMigrator is an open source project to manage the schema of your data bases, claims to be a .Net implementation similar to Ruby on Rails Migrations
, you should post issues and feedback in the issues or discussion forum for that project on github as their community is still active in 2020.
因为 Fluent Migrator 本身不是 ORM,它只管理数据模式,因此问题不正确。
EF 有自己的模式迁移管理,Code First Migrations 解释 [NotMapped]
以从数据库模式中省略字段,并在将查询结果映射到数据对象模型时忽略它。
从 EF 到 NHibernate 或 Dapper 的项目转换通常是 NHibernate 或 Dapper,对于此响应,我将假定 NHibernate,因为如果您仍在使用 EF,则问题不存在,但希望思考过程将帮助您找到答案,如果您是使用不同的 ORM。
回复:NotMapped
如上所述,EF 中的 NotMapped
属性由数据架构迁移 和 ORM 解释。在 Fluent Migrator 的配置中,您手动指定要在数据模式中操作的字段,因此只需从 Create/Alter table 语句中完全省略该字段。
如果要更改字段以不再存储在数据库中,则可以添加 Delete.Column
命令:
Delete.Column("ColumnName".FromTable("TableName").InSchema("dbo");
更新:Linq2Db 解决方案:
Use NotColumn attribute
在像NHibernate这样的ORM中也是如此,只是不要在映射配置中映射属性。
当您使用 NHibernate 的自动映射扩展时,- This post 经历了不同的解决方案。
回复:AsNoTracking
如果您仍在使用 EF6 作为 ORM,那么这不会改变,Fluent Migrator 是
关于架构维护和操作,而不是数据查询。
AsNoTracking()
在 EF 查询中禁用更改跟踪和缓存,并且作为副产品允许在单个响应中查询 return 多个具有重复键值的记录,OP 不清楚使用的上下文 AsNoTracking()
,但重要的是要确定为什么使用 'might',
更新:linq2Db
据我所知,Linq2Db 不跟踪更改,其主要功能是将 Linq 查询转换为 SQL 并执行 SQL,即 AsNoTracking
具有缓存影响所以我在 linq2db 中找到的最接近的是使用 NoLinqCache 创建一个不会缓存执行的范围:
using (var db = new MyDataConnection())
using (NoLinqCache.Scope())
{
var query = db.Users.Where(x => Sql.Ext.In(x.Id, ids));
}
For readers using NHibernate, you can consult the read-only entities documentation.
You can set al queries in a session as readonly using
session.DefaultReadonly = true
Alternatively you can set a single query to be readonly:
query.SetReadonly(true);
Fluent Migrator .Net ORM 中 NotMapped 属性和 AsNoTracking 方法的等效项是什么?我正在将我使用 EF6 作为 ORM 的项目之一迁移到 Fluent Migrator。我 google 对此有很多了解,但找不到任何有用的信息。
FluentMigrator is an open source project to manage the schema of your data bases, claims to be a .Net implementation similar to
Ruby on Rails Migrations
, you should post issues and feedback in the issues or discussion forum for that project on github as their community is still active in 2020.
因为 Fluent Migrator 本身不是 ORM,它只管理数据模式,因此问题不正确。
EF 有自己的模式迁移管理,Code First Migrations 解释 [NotMapped]
以从数据库模式中省略字段,并在将查询结果映射到数据对象模型时忽略它。
从 EF 到 NHibernate 或 Dapper 的项目转换通常是 NHibernate 或 Dapper,对于此响应,我将假定 NHibernate,因为如果您仍在使用 EF,则问题不存在,但希望思考过程将帮助您找到答案,如果您是使用不同的 ORM。
回复:NotMapped
如上所述,EF 中的 NotMapped
属性由数据架构迁移 和 ORM 解释。在 Fluent Migrator 的配置中,您手动指定要在数据模式中操作的字段,因此只需从 Create/Alter table 语句中完全省略该字段。
如果要更改字段以不再存储在数据库中,则可以添加 Delete.Column
命令:
Delete.Column("ColumnName".FromTable("TableName").InSchema("dbo");
更新:Linq2Db 解决方案:
Use NotColumn attribute
在像NHibernate这样的ORM中也是如此,只是不要在映射配置中映射属性。
-
当您使用 NHibernate 的自动映射扩展时,
- This post 经历了不同的解决方案。
回复:AsNoTracking
如果您仍在使用 EF6 作为 ORM,那么这不会改变,Fluent Migrator 是 关于架构维护和操作,而不是数据查询。
AsNoTracking()
在 EF 查询中禁用更改跟踪和缓存,并且作为副产品允许在单个响应中查询 return 多个具有重复键值的记录,OP 不清楚使用的上下文 AsNoTracking()
,但重要的是要确定为什么使用 'might',
更新:linq2Db
据我所知,Linq2Db 不跟踪更改,其主要功能是将 Linq 查询转换为 SQL 并执行 SQL,即 AsNoTracking
具有缓存影响所以我在 linq2db 中找到的最接近的是使用 NoLinqCache 创建一个不会缓存执行的范围:
using (var db = new MyDataConnection())
using (NoLinqCache.Scope())
{
var query = db.Users.Where(x => Sql.Ext.In(x.Id, ids));
}
For readers using NHibernate, you can consult the read-only entities documentation.
You can set al queries in a session as readonly usingsession.DefaultReadonly = true
Alternatively you can set a single query to be readonly:
query.SetReadonly(true);