EF映射以在表中前缀所有列名 [英] EF Mapping to prefix all column names within a table
问题描述
Tablename:地址
列:
addressId
addressLine1
addressLine2
是否有任何配置可以应用映射(使用流畅的API),其中我可以指定所有列名称以字符串为前缀例如地址?否则我将需要定义每一个单独的列映射,这似乎有点痛苦。
更好的是,如果我可以编写一个约定,其中前缀是自动从de-pluralize tablename中设置,但是我知道在这一点上不支持自定义约定,所以我猜这是不太可行的。
您可以编写自己的约定引擎,这不是很难。
以下是如何: http://sessionfactory.blogspot.com/2011/04/conventions-in-entity-framework-41 .html
I have a large existing database which has a convention where all the column names are prefixed with the de-pluralised tablename, e.g.
Tablename: addresses
Columns:
addressId
addressLine1
addressLine2
Is there any configuration I can apply for a mapping (using the fluent API) where I can specify that all column names are prefixed with a string e.g. "address"? Otherwise I will need to define every single column mapping, which seems a bit of a pain.
What would be even better is if I could write a convention where the prefix is automatically set from the de-pluralised tablename, but I am aware that custom conventions are not supported at this point, so I guess this is even less feasible.
You can write your own conventions "engine", it's not terribly hard.
Here's how: http://sessionfactory.blogspot.com/2011/04/conventions-in-entity-framework-41.html
这篇关于EF映射以在表中前缀所有列名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!