How to get a DBTableField

Posts   
 
    
spud19
User
Posts: 2
Joined: 25-Apr-2016
# Posted on: 27-Apr-2016 15:44:38   

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.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39568
Joined: 17-Aug-2003
# Posted on: 27-Apr-2016 15:46:07   

You asked this here: http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=23782 I asked for more info. Please provide that, as otherwise we can't help you.

Frans Bouma | Lead developer LLBLGen Pro