Is it possible to generate a different column name for a property when generating SQL schema from the .edmx file?
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 c开发者_如何学JAVAolumn 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.
I abandoned this in favor of fully code-first, but I think there's a way to do it:
- In the model, use column names.
- Generate SQL from the
.edmx
. - 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.
精彩评论