What's the equivalent of NotMapped attribute and AsNoTracking method in Fluent Migrator .Net ORM. I'm migrating one of my project which used EF6 as ORM to Fluent Migrator. I google a lot regarding this but couldn't find any helpful information.
-
You should include an example of the code you are converting or the usage where you are expecting both cases, you have also asked two distinct questions here, one is in regard to class design and configuration, the other is related to execution... – Chris Schaller Jul 30 '20 at 02:12
-
Fluent Migrator replaces EF Code First Migrations, but it does not replace EF as an ORM, what ORM are you using? – Chris Schaller Jul 30 '20 at 02:46
-
@ChrisSchaller linq2Db is the ORM I'm using – Optimus Jul 30 '20 at 04:57
-
I've updated my solution, we're not supposed to use this as a discussion, but why are you transitioning from EF if you are using migrations and change tracking? Sounds like you might be paddling in the wrong direction. – Chris Schaller Jul 30 '20 at 06:16
-
@ChrisSchaller we are using nopCommerce framework and upgrading to their newest version. In the latest nopCommerce framework they replaced EF with Fluent Migrator and Linq2Db – Optimus Jul 30 '20 at 06:18
-
then you should have posted in their forum, if someone else tells you to change frameworks between versions, they will usually have guidance around how to achieve this change, you wont be the only person in this situation, see: https://www.nopcommerce.com/en/boards – Chris Schaller Jul 30 '20 at 06:21
-
@ChrisSchaller their forums are not this much active – Optimus Jul 30 '20 at 06:22
-
Their forums are very active, last post 6 mins ago! – Chris Schaller Jul 30 '20 at 06:25
1 Answers
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.
Because Fluent Migrator is not an ORM itself, it only manages the data schema, the question is therefor not properly formed.
EF has it's own schema migration management, Code First Migrations that interprets [NotMapped]
to omit the field from the database schema, and to ignore it when mapping results of queries into the data object model.
Project transitions from EF are commonly to NHibernate or Dapper, for this response I will assume NHibernate, because if you were still using EF the problem does not exist but hopefully the thought process will help you find the answer if you are using a different ORM.
RE: NotMapped
As elaborated above, the NotMapped
attribute in EF is interpreted by both the data schema migrations AND the ORM. In the configuration for Fluent Migrator you manually specify the fields to manipulate in the data schema, so simply omit the field from Create/Alter table statements altogether.
If you are changing a field to be no longer stored in the database, then you can add a Delete.Column
command:
Delete.Column("ColumnName".FromTable("TableName").InSchema("dbo");
UPDATE: Linq2Db solution:
Use NotColumn attribute
In ORMs like NHibernate the same is true, simply do not map the property in the mapping configuration.
- This post goes through different solutions when you are using an auto-mapping extension for NHibernate.
RE: AsNoTracking
If you are still using EF6 as the ORM, then this doesn't change, Fluent Migrator is about schema maintenance and manipulation, not data querying.
AsNoTracking()
in an EF query disables change tracking and caching and as a by-product allows a query to return multiple records with duplicate key values in a single response, it is unclear from OP what context AsNoTracking()
is being used, but important to identify why is 'might' be used,
UPDATE: linq2Db
As far as I'm aware, Linq2Db does not track changes, its primary function is to translate Linq queries into SQL and execute that SQL, that said AsNoTracking
has caching implications so the closest I can find in linq2db is to use NoLinqCache to create a scope where the executions will not be cached:
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);

- 13,704
- 3
- 43
- 81
-
Updated this answer to include Linq2db solutions as the specific ORM was originally omitted by OP – Chris Schaller Jul 30 '20 at 06:13