Hi all,
I want to had something like this in my generated c#
[Column(TypeName = "nvarchar")]
My file dbContextEntityClass.lpt looks like this :
Project currentProject = _executingGenerator.ProjectDefinition;
bool emitForeignKeyFields = currentProject.GetRealBoolSettingValue("EmitForeignKeyFields");
EntityDefinition entity = (EntityDefinition)_activeObject;
bool isSubType = entity.IsSubType;
var allRelationshipInfosToTraverse = GeneratorUtils.GetAllRelationshipInfosForEntity(_executingGenerator, entity)
.Where(ri=>((ri.RelationshipType==EntityRelationshipType.ManyToMany) &&
((IndirectRelationshipEdge)ri.Relationship).IsPureManyToMany) ||
((ri.RelationshipType!=EntityRelationshipType.ManyToMany) &&
!ri.NormalRelationship.EntityFkSide.IsPureManyToManyIntermediate))
.ToList();
var entityFields = entity.Fields.Where(f=>!f.IsDiscriminator).OrderBy(f=>f.FieldIndex).ToList();
if(!emitForeignKeyFields)
{
entityFields = entityFields.Where(f=>!f.IsForeignKeyField || (f.IsForeignKeyField && f.IsPartOfIdentifyingFields)).ToList();
}
string propertyAccessor = currentProject.GetRealBoolSettingValue("PublicPropertyGettersAndSetters") ? "public" : "private";
bool emitKnownTypeAttributes = entity.OutputSettingValues.GetRealBoolSettingValue("EmitKnownTypeAttributesForWCF", currentProject);
_executingGenerator.StoreValueInRunQueueCache("EntityClassesNamespace", _executingGenerator.RootNamespaceToUse + ".EntityClasses");
.....
foreach(IFieldElementCore field in entityFields)
{
****
if( ( (! field.IsOptional) && (!field.FieldType.ToString().Contains("EITSvcStamp")))
|| ( (! field.IsOptional) && (bCurrentIsDbo == true) ) )
{
%> [Required]
<% }
if(
(
field.FieldType.ToString().Contains("string")
||
field.FieldType.ToString().Contains("NotLocalized")
) && field.MaxLength != 0
) {
%> [StringLength(<%=field.MaxLength%>)]
<%
}
DBTableField dbField = (DBTableField)entity.Fields[field.FieldIndex].MappedField;
//DBTableField dbField = (DBTableField)entity.Fields[field.FieldIndex ].MappedField;
//DBTableField dbField = field.TypeDefinition.DBTypeAsString.ToLowerInvariant();
if (dbField.TypeDefinition.DBTypeAsString.ToLowerInvariant().Contains("varchar"))
{
%> //[Column(TypeName = "nvarchar")]
<%
}
****
//I need help here :
var dbField = entity.FieldsMappedOntoRelatedFields;
//DBTableField dbField = (DBTableField)entity.Fields[field.FieldIndex ].MappedField;
//DBTableField dbField = field.TypeDefinition.DBTypeAsString.ToLowerInvariant();
if (dbField.TypeDefinition.DBTypeAsString.ToLowerInvariant().Contains("varchar"))
{
%> //[Column(TypeName = "nvarchar")]
<%
}
****
}
I would like to know how to get in the target element detail the DB type. It's sounds really easy. But can't find the way.
Tks in advance.
S.