1

I'm doing a DB-First generation of a DbContext and POCO objects with EF6 and having the same issues as many others re the navigation property names being unhelpful in describing relationships to other tables.

e.g If a Person has a Home and Work address, it would be reflected in the object as

public class Person {
    public virtual DbSet<Address> Address; 
    public virtual DbSet<Address> Address1;
}

This question is on the right track for EF5, however neither the tool nor the code solution supports the t4 template generated by EF6. Improve navigation property names when reverse engineering a database

What's the easiest way I can replace the above with

public class Person {
    public virtual DbSet<Address> Home; 
    public virtual DbSet<Address> Work;
}

AND be able to regenerate the edmx file when I need to from scratch (i.e manually modifying 100 tables via the vs2013 GUI is not what I'm looking for).

I've looked around the forums and have started using the debug T4 Template tool but hoping there is a easier out than DIY.

Community
  • 1
  • 1
Joe
  • 11,147
  • 7
  • 49
  • 60
  • Are you using both: edmx and POCO objects? – Vladimir Sachek May 15 '14 at 08:39
  • yes, as far as i understand it, the edmx is used to create the poco objects so i don't see how i can have one without the other? Doing via adding 'ADO.Net Entity Data Model' through vs and it creates the DbContext via the edmx and POCO objects for me. – Joe May 15 '14 at 08:41

1 Answers1

1

If you don't need edmx, then you can remove it at all and reverse your database into Code First using EF Power Tools. After that use any tool that will help with property renames e.g Resharper

Vladimir Sachek
  • 1,126
  • 1
  • 7
  • 20
  • At this point in time, i think migrating from DB first to Code first is out of scope. Ideally, I would like to head in that direction but for now I'd prefer to edit the T4 to generate friendly navigation properties for edmx. Shouldn't be too hard right? – Joe May 15 '14 at 08:51
  • i cannot give you enough rep for this... didn't realise how easy it was with code first reverse enginnering to move away from a database first model. Thank you! You've made my day! (It took me but 1hr to work out how to switch it out, switch it, test it and now i can get rid of all those metadata files for data annotations) – Joe May 15 '14 at 09:44
  • Cool! Yes, it is very easy to do if your model and database doesn't differ much. I had 1 small issue with some navigation properties, because they were not marked as virtual for some reason and therefore lazy loading didn't work for them. – Vladimir Sachek May 15 '14 at 09:48