I have a scenario where if certain features are deployed then a number of columns will be there in some tables otherwise won't so the mapping of Entities and Columns is not static. I need to add/remove the mapping at runtime. Is there any way?
Asked
Active
Viewed 721 times
1 Answers
1
Prepare a new MappingSchema
and pass to DataConnection
constructor.
Consider you have the following class:
[Table]
class SampleClass
{
[Column] public int Id { get; set; }
[Column] public int Value { get; set; }
}
To remove column from full object materialization, do the following:
var ms = new MappingSchema();
ms.GetFluentMappingBuilder()
.Entity<SampleClass>().Property(e => e.Value).IsNotColumn();
// cache somewhere this schema
using (var db = new DataConnection(ms))
{
var result = db.GetTable<SampleClass>().ToArray();
}
Remember, better to cache this new MappingSchema
and reuse. Otherwise you will never have cache hit and you'll lose performance.

Svyatoslav Danyliv
- 21,911
- 3
- 16
- 32
-
It worked but what if there are multiple tables/entities involved? – bjan Nov 26 '20 at 14:56
-
.Entity
().Property(e => e.Value).IsNotColumn() .Entity – Svyatoslav Danyliv Nov 26 '20 at 15:17().Property(e => e.Value).IsNotColumn() .Entity ().Property(e => e.Value).IsNotColumn()