In a T4 template file, how do I validate the datatype of a property in an entity?

c# entity entity-framework t4 templates

Question

In EF 4.0, I'm modifying my.tt file. I now need to add some code to a property in the creation of the POCO class as part of customisation, if the property type isNullable<System.DateTime> or System.DateTime . I cannot locate the appropriate syntax for comparison.

I have the code shown below in a.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.
}

Thank you.

1
9
2/12/2011 9:00:02 PM

Accepted Answer

  if (((PrimitiveType)edmProperty.TypeUsage.EdmType).
        PrimitiveTypeKind == PrimitiveTypeKind.DateTime && edmProperty.Nullable)
12
2/16/2013 12:13:22 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow