0

I'm using Reverse Engineered Code First code and see stubs like:

public class User
{
    public User()
    {
        this.Addresses = new List<Address>();
        ...
    }

    public int ID { get; set; }
...
}

When, based on this question, i'd expect to see partial classes.

Wouldn't this change the preferred way of extending the generated classes with my own code (which is very nicely summarized in the linked answer, btw)?

thx

Community
  • 1
  • 1
justSteve
  • 5,444
  • 19
  • 72
  • 137

2 Answers2

2

There is a way to customize the output of the entity objects by changing the TT files.

Rowan Miller has an excellent blog post on how to do it.

In your example, you can update the Entity.TT file that's int he template

From this:

public class <#= efHost.EntityType.Name #>

To this:

public partial class <#= efHost.EntityType.Name #>

and it will create the partial classes you're looking for.

Mark Oreta
  • 10,346
  • 1
  • 33
  • 36
  • I get the general theory of TT's usage but am looking to understand what looks like a conscious choice by the folks behind the Power Tools to not be partial. – justSteve Aug 03 '12 at 18:51
2

Our aim was to generate the simplest classes possible, as close to what you would write by hand as we could. There is no problem changing them to be partial - that's exactly the kind of reason we made the generation customizable.

~Rowan

Rowan Miller
  • 2,090
  • 15
  • 15
  • Rowan, is it possible to query the extended properties from SQL Server? I would like to decorate the classes like /// /// /// Description from SQL Server Extend Properties /// public string Example { get; set; } Thanks. – Steve Nov 09 '12 at 23:42