Using templates

Image

In the last chapter I walked you through using the DbContext template to change the code that the Entity Model Designer produces. But I don’t want you to just memorize a series of steps, and that’s all you can do if you don’t understand why you’re doing them. So let’s back up now and look at what’s actually going on with this whole template business.

Two things work together to determine the code generated by the Entity Model Designer: the model’s Code Generation Strategy property and the Custom Tool property of the model file.

By default

Image

When you set a code generation item

Image

Image On Your Own

You don’t really need my help to change the template the designer is using in our application—after all, you’ve already done it. So why don’t you try it, and then explore a little?

Change the generation item to ADO.NET Entity Object Generator. (Check back to page 146 if you’ve forgotten the details.

 

Are there any visible changes in the primary designer surface?

 

 

What items are added to the project? (Hint: Check the Solution Explorer.)

 

 

If you select Model1.tt in the Solution Explorer, what custom tool is used to generate the file? (Hint: Check the Properties Window.)

 

 

If you select a blank area of the primary designer surface, what is the code generation strategy?

 

 

If you open the ModelFirstRecipe.Designer.cs or ModelFirstRecipe.Designer.vb file, what does it contain?

What does the Model1.cs or Model1.vb file contain?

 

 

Does the generated code seem different from the default code generated by the Designer?

 

 

Why do you think you’d bother using a T4 template to generate the same code that is generated by default?

 

 

What does the Model1.tt file contain?

 

 

What happens if you set the Code Generation Strategy propery of the model back to default? What does the ModelFirstRecipe.Designer.cs or ModelFirstRecipe.Designer.vb file contain now?

 

 

If you make a change to the model and save it, which files are updated?

 

 

Can you think of a situation in which it might be useful to maintain multiple versions of the code?

 


..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset