Quantcast
Channel: MySQL Forums - Connector/NET and C#, Mono, .Net
Viewing all articles
Browse latest Browse all 1451

T4 Template (no replies)

$
0
0
Hallo,
i'm a .net developer and i analized the T4 model template that generate the database from an entity framework model first, particurarly the WriteMySqlType method incuded in a GenerateMySQL.Utility.ttinclude file.

this is my personal idea to modify this method, but i'am no expert in database development

private static string WriteMySqlType(EdmProperty property)
{
if (property.TypeUsage.EdmType.Name == "guid")
return "char(36) binary";
else if(property.TypeUsage.EdmType.Name == "bool")
return "tinyint(1)";
else if( property.TypeUsage.EdmType.Name == "nchar" )
{
if( property.TypeUsage.Facets.Contains( "FixedLength" )
&& (bool)property.TypeUsage.Facets[ "FixedLength" ].Value )
{
int len = ( int )( property.TypeUsage.Facets[ "MaxLength" ].Value );
return string.Format( "char( {0} )", len );
}
else
return return property.ToStoreType();

}
else if( property.TypeUsage.EdmType.Name == "nvarchar" )
return string.Format( "varchar( {0} )", property.TypeUsage.Facets[ "MaxLength" ].Value );
else if( property.TypeUsage.EdmType.Name == "mediumtext" )
{
int len = ( int )( property.TypeUsage.Facets[ "MaxLength" ].Value );
if(len <= 255)
return string.Format( "varchar( {0} )", len );
else if (len > 255 && len <= 65536 )
return "text";
else if(len >= 65536 && len < 16777216 )
return "mediumtext";
else
return "longtext";
}
else if( property.TypeUsage.EdmType.Name == "longtext" )
return "longtext";
else if( property.TypeUsage.EdmType.Name == "varbinary" )
{
int len = ( int )( property.TypeUsage.Facets[ "MaxLength" ].Value );
if( len > 255 && len < 65536)
return "blob";
else if( len >= 65536 && len < 16777216)
return "mediumblob";
else
return "longblob";
}
else if ( property.TypeUsage.EdmType.Name == "datetime")
{
if( property.TypeUsage.Facets.Contains( "StoreGeneratedPattern" )
&& property.TypeUsage.Facets[ "StoreGeneratedPattern" ].Value.ToString() == "Computed" )
{
//Force to be a timestamp datatype
return "timestamp";
}
else
return property.ToStoreType();
}
else
return property.ToStoreType();
}

unfortunately if fixedlength is false in the edm property, maxlength is a constant :(.

best regards,
Luca Graziani.

Viewing all articles
Browse latest Browse all 1451

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>