如何检查T4模板文件中实体的属性的数据类型

WPF*_*mer 9 c# t4 templates entity entity-framework

我在EF 4.0中自定义我的.tt文件.现在作为自定义的一部分,我需要在POCO类生成中向属性添加一些代码,如果属性类型是Nullable<System.DateTime>System.DateTime.我无法找到适当的比较语法.

我在.tt文件中有以下代码.

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.
}
Run Code Online (Sandbox Code Playgroud)

请帮忙.

WPF*_*mer 12

  if (((PrimitiveType)edmProperty.TypeUsage.EdmType).
        PrimitiveTypeKind == PrimitiveTypeKind.DateTime && edmProperty.Nullable)
Run Code Online (Sandbox Code Playgroud)