1

I've "inherited" an EF 4.0 .edmx file. Currently a given property name and column name are identical in the generated C# and SQL schema. I've since upgraded to EF 4.1, and changed the code generation item to generate a DbContext instead of an ObjectContext.

What I want to do is generate a SQL schema where the column names could be different. For example, say I have an Id property/column for Product; I want to generate Id for the class (via the T4 template generation) and ProductId for the column (somehow via the Generate Database from Model... context menu entry from the diagram), and then use the code-based fluent configuration capabilities to map the two via EntityTypeConfiguration<T>.HasColumnName().

Can I do this or is there a reasonable alternative? I realize I can do this all in code using 4.1, but wondering if this "transitional" approach is possible.

abatishchev
  • 98,240
  • 88
  • 296
  • 433
Kit
  • 20,354
  • 4
  • 60
  • 103
  • Good question - its easy enough to do when the schema already exists, via mapping, but now I'm curious about doing it this way as well... – The Evil Greebo Jun 15 '11 at 14:22

1 Answers1

0

I abandoned this in favor of fully code-first, but I think there's a way to do it:

  1. In the model, use column names.
  2. Generate SQL from the .edmx.
  3. In the T4 template, read from a mapping file of some kind (e.g. csv) and apply some logic to generate the C# classes as desired and to generate the HasColumnName calls.

this should work, but involves more effort than I'm willing to give on creating the right template.

Kit
  • 20,354
  • 4
  • 60
  • 103
  • I came across this issue as well. No idea how to do it. But I agree with you that code-first is a better way anyway. But it would still be good to know this. – lahsrah Aug 03 '11 at 21:57