Home
Help
Register
Log in

Search

 
   Active Threads  

You are here: Home > LLBLGen Pro > Custom Templates> How to get a DBTableField
 

Pages: 1
Custom Templates
How to get a DBTableField
Page:1/1 

  Print all messages in this thread  
Poster Message
spud19
User



Location:

Joined on:
25-Apr-2016 11:53:22
Posted:
2 posts
# Posted on: 27-Apr-2016 15:44:38.  
Hi all,

I want to had something like this in my generated c#

Code:
[Column(TypeName = "nvarchar")]


My file dbContextEntityClass.lpt looks like this :

Code:


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.
  Top
Otis
LLBLGen Pro Team



Location:
The Hague, The Netherlands
Joined on:
17-Aug-2003 18:00:36
Posted:
37186 posts
# 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
LLBLGen Pro / ORM Profiler Lead Developer | Blog | Twitter
 
Top
Pages: 1  


Powered by HnD ©2002-2007 Solutions Design
HnD uses LLBLGen Pro

Version: 2.1.12172008 Final.