Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to not need to substitute ICollection to ObservableCollection in TT-file?

Every time I create a new data model with EF, I have to enter the TT file and substitute each occurrence of ICollection and the first occurrence of HashSet for ObservableCollection as well as the namespace Generic for ObjectModel.

The process is described on the internet (the bullet list right above "Lazy Loading" section) and seems to be as a hacky work-around for a shortcoming of a new technology, which with time should have been remedied and not needed.

Is it possible to automatically create observable collection or is the approach described the most efficient and generally applied?

like image 528
Konrad Viltersten Avatar asked Aug 05 '15 12:08

Konrad Viltersten


1 Answers

I think customizing a .TT template for your need is an acceptable (or more: best) practice. The only question, Do this customizing process repeatedly/manually or create your own .TT and install it as Visual Studio Item Template. My vote goes to this second option, which is a little application of DRY.

However you need to prepare yourself to a drawback: When original .TT item templates will change (new version, etc) then you should apply those changes on your custom templates too. The easiest way to do this: diff, then choose the most efficient way: Replicate version changes on your custom template or reapply your customization changes on the new version.

like image 193
g.pickardou Avatar answered Nov 09 '22 22:11

g.pickardou