How to Add common and Explicit mapping together in fluent mapping #408
Unanswered
nagtilaklaxman
asked this question in
Q&A
Replies: 1 comment 1 reply
-
I guess it's possible. You want to have a 1-1 mapping with a custom action on an interface You'll need to add some type checking: // Define a function that returns true for the common entities depending on the type
private bool IsCommonEntity(Type type)
{
return type == typeof(Order) || type == typeof(Orderline);
}
Audit.Core.Configuration.Setup()
.UseEntityFramework(ef => ef
.AuditTypeExplicitMapper(config => config
.Map<Order, OrderAudit>()
.Map<Orderline, OrderlineAudit>()
.MapExplicit<AuditLog>(ee => !IsCommonEntity(ee.GetEntry().Entity.GetType()), (entry, auditLog) =>
{
auditLog.AuditData = entry.ToJson();
auditLog.EntityType = entry.EntityType.Name;
auditLog.AuditDate = DateTime.Now;
auditLog.AuditUser = Environment.UserName;
auditLog.TablePk = entry.PrimaryKey.First().Value.ToString();
})
.AuditEntityAction((evt, entry, entity) => // use the non-generic overload
{
if (entity is IAudit auditEntity) // only for the entities implementing IAudit
{
auditEntity.AuditDate = DateTime.UtcNow;
auditEntity.UserName = evt.Environment.UserName;
auditEntity.AuditAction = entry.Action;
}
}))
.IgnoreMatchedProperties(type => type == typeof(AuditLog))); // Ignore matched properties for entities mapped to AuditLog |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
How I can use type mapper and explicit mapper together?
Want some entity that should go to a specific log table and all others to the common log table.
----specific
----Common ---
Beta Was this translation helpful? Give feedback.
All reactions