I'm dealing with a legacy database that has a locked schema. The problem I'm facing is that a number of the tables are keyed off known/fixed/hard-coded entity type Id values instead of having a column values. This means that I can't use the normal References construct.
For the tables with the ENTITY_TYPEID I can do this:
public class EntityMap : ClassMap<Entity>
{
public EntityMap()
{
References(x => x.Type)
.Columns("ENTITY_SECTION","ENTITY_TYPEID");
}
}
which happily populates the Entity.Type.
For the tables of a fixed/known/hard-coded type I need to map to a hard-coded value instead of the ENTITY_TYPE column, so to para-phrase in code:
public class EntityXMap : ClassMap<EntityX>
{
public EntityXMap(int entityType)
{
References(x => x.Type)
.Columns("ENTITY_SECTION", "ENTITY_TYPE = 123" );
}
}
HasMany() has a Where() construct that I could use in that case...
Any ideas how to achieve something similar here?
maybe overkill but you could try
// add to config
var typemap = new TypeMap();
typemap.Id(x => x.Section, "ENTITY_SECTION");
typemap.Where("ENTITY_TYPE = 123");
typemap.EntityName("Type for EntityX");
References(x => x.Type)
.Column("ENTITY_SECTION")
.EntityName("Type for EntityX");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.