Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check the datatype of a property in an entity in a T4 template file

I am customizing my .tt file in EF 4.0. Now as part f customization I need to add some code to a property in POCO class generation, if the property type is Nullable<System.DateTime> or System.DateTime. I am not able to find the proper syntax for comparison.

I have the following code in .tt file.

foreach (EdmProperty edmProperty in entity.Properties.Where(p => p.TypeUsage.EdmType is PrimitiveType && p.DeclaringType == entity))
{
bool isDefaultValueDefinedInModel = (edmProperty.DefaultValue != null);
//Here I need to check whether my edmProperty is Nullable<System.DateTime> or System.DateTime, so that I can insert custom code.
}

Please help.

like image 935
WPFProgrammer Avatar asked Feb 11 '11 06:02

WPFProgrammer


1 Answers

  if (((PrimitiveType)edmProperty.TypeUsage.EdmType).
        PrimitiveTypeKind == PrimitiveTypeKind.DateTime && edmProperty.Nullable)
like image 143
WPFProgrammer Avatar answered Oct 23 '22 17:10

WPFProgrammer