Hello,
In a project to be ported from BL Gen 2.6 to LBL Gen 5.9, fields are added to entities in several places.
For example, the following function is used to transfer fields found in an MS SQL model to an Oracle model.
private EntityFieldDefinition AddFieldToEntity(EntityDefinition oracleEntity, EntityFieldDefinition sqlserverFieldDef)
{
IEntityFieldMapTargetElement oraField = null;
if (oracleEntity.TargetType == EntityMapTargetElementType.Table)
{
DBTableField oraTableField = new DBTableField();
oraTableField.ParentTable = (IDBTable)oracleEntity.Target;
oraTableField.FieldName = sqlserverFieldDef.MappedField.FieldName;
oraTableField.OrdinalPosition = sqlserverFieldDef.MappedFieldOrdinalPosition;
oraTableField.IsComputed = sqlserverFieldDef.MappedFieldIsComputed;
oraTableField.TypeDefinition.DBTypeAsNETType = sqlserverFieldDef.DotNetType;
oraTableField.TypeDefinition.DBType = OracleDotNetTypeMapper.GetMatchingOracleType(oraTableField.TypeDefinition.DBTypeAsNETType);
oraTableField.TypeDefinition.DBTypeAsString = OracleDotNetTypeMapper.GetTypeAsString(oraTableField.TypeDefinition.DBType);
oraTableField.TypeDefinition.RequiresInsertValue = false;
oraField = oraTableField;
}
else
{
DBViewField oraViewField = new DBViewField();
oraViewField.ParentView = (IDBView)oracleEntity.Target;
oraViewField.FieldName = sqlserverFieldDef.MappedField.FieldName.ToUpperInvariant();
oraViewField.OrdinalPosition = sqlserverFieldDef.MappedFieldOrdinalPosition;
oraViewField.IsComputed = sqlserverFieldDef.MappedFieldIsComputed;
oraViewField.TypeDefinition.DBTypeAsNETType = sqlserverFieldDef.DotNetType;
oraViewField.TypeDefinition.DBType = OracleDotNetTypeMapper.GetMatchingOracleType(oraViewField.TypeDefinition.DBTypeAsNETType);
oraViewField.TypeDefinition.DBTypeAsString = OracleDotNetTypeMapper.GetTypeAsString(oraViewField.TypeDefinition.DBType);
oraViewField.TypeDefinition.RequiresInsertValue = false;
oraField = oraViewField;
}
ProjectProperties properties = oracleEntity.Container.ContainingProject.Properties;
EntityFieldDefinition result = oracleEntity.MapField(oraField, properties);
return result;
}
I am now looking for an approach to enable something similar as universal as possible for the new LLBL Gen version.
The difficulty here seems to lie in providing the right data type. The old version solves this by using the represent C# types.
I'm also not sure if the DBTableField and DBViewField part is necessary anymore.
My idea is to clone the Ms SQL Field and change the problematic values afterwards. Is this approach ralistic? And can I create the FieldType using the C# type?
var returnField = sqlserverFieldDef.Clone(oracleEntity, sqlserverFieldDef.Name);
returnField.FieldType = new ???;
regards,
relevart