Search code examples
entity-frameworkpocoentity-framework-4.1edmxdatabase-first

EF 4.1 DbContextGenerator object names - can they be changed?


I am using DB First EF 4.1 and I am adding DbContextGenerator tt template to my model. This is all great, but I end up with classes like this:

public partial class t_city
{
    public t_city()
    {
        this.t_neighborhood = new HashSet<t_neighborhood>();
    }

    public int city_id { get; set; }
    public string city_name { get; set; }

    public virtual ICollection<t_neighborhood> t_neighborhood { get; set; }
}

This is super ugly. I modified the template to generate properties in camelcase, but that breaks the mapping onto tables and columns. Is there way to get clean class names and still preserve the mapping?

EDIT

Looks like it's possible by renaming the objects inside the Entity Model file. The only question remains, is it possible to automate the renaming using a function, or does it have to be done manually each time?

Thanks!


Solution

  • You need to do it manually but that's needed only once for each entity / property. These changes are not deleted when you update your model from the database.

    The only automation can be implemented as some processing of EDMX file. It is XML with defined schema so you can process that XML in your custom tool or XSLT transformation and automatically change property and entity names in CSDL and MSL.