sjh37 / EntityFramework-Reverse-POCO-Code-First-Generator

EntityFramework Reverse POCO Code First Generator - Beautifully generated code that is fully customisable. This generator creates code as if you reverse engineered a database and lovingly created the code by hand. It is free to academics (you need a .edu or a .ac email address), not free for commercial use. Obtain your licence from
https://www.reversepoco.co.uk/
Other
706 stars 230 forks source link

Question: Replacement for UseDataAnnotationsWithFluent? #757

Closed lukos closed 2 years ago

lukos commented 2 years ago

Upgrading from v2 to v3 and I've noticed that this setting is not there any more. We used to use it to add non EF attributes to columns (as per the v2 description), like MaxLength and Display.

How do we do this now while keeping the fluent generation?

Thanks

lukos commented 2 years ago

And also ColumnNameToDataAnnotation seems to have been removed. We used it for adding DataType attributes. I can obviously put something back in manually but maybe this functionality was intended to be changed to use something else that I can't find?

sjh37 commented 2 years ago

Hi Luke, At approx line 93 in your <database>.tt file, set

Settings.UseDataAnnotations = true;

The ColumnNameToDataAnnotation has been removed in v3 as it was not longer required. Data annotations are now handled in your <database>.tt file which makes it customisable. See the Settings.UpdateColumn callback approx line 311.

lukos commented 2 years ago

Thanks @sjh37 it seems mostly OK although ColumnNameToDataAnnotation was neater because we only had to set this in settings and it applied it automatically. The way it is done now, I have to manually created the dictionaries and also work out the code to apply the annotations if there is an entry, which is pretty much copied from the v2 template.

Having a very generic method is obviously powerful but it would be nice to include some of the common features that were in the older version to avoid re-inventing the wheel.