EF映射以在表中前缀所有列名 [英] EF Mapping to prefix all column names within a table

查看:139
本文介绍了EF映射以在表中前缀所有列名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个大型现有的数据库,它有一个约定,其中所有的列名称都带有去复数形式的tablename,例如

  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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆