The “Reverse Engineer Code First” functionality of Entity Framework Power Tools, Beta 2 is very good and I am working on customising the Reverse Engineer Templates.
In Entity.tt, take a look at the following line (line breaks introduced):
<#= Accessibility.ForProperty(property) #>
<#= code.Escape(property.TypeUsage) #>
<#= code.Escape(property) #>
{ get; set; }
For a database column named “SomeDate” of type datetime, you will have the following code outputted:
public Nullable<System.DateTime> SomeDate { get; set; }
How can I modify the Entity.tt code to produce this instead:
public DateTime? SomeDate { get; set; }
Thank you,
R.
As podiluska mentioned, you need to edit EF.Utility.CS.ttinclude (you can see that this is imported by Entity.tt if you follow the “Customize Reverse Engineer Templates” instructions here)
On my machine it is here:
C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\Extensions\Microsoft\Entity Framework Tools\Templates\Includes
Around line 127, replace
With
Make sure you test this. It worked fine for me, but I can’t guarantee that it will work for all nullable types. Any comments would be appreciated and I will edit this post as appropriate