实体框架:数据库表/列中案例(如帕斯卡案例)的最佳实践

发布于 2024-09-25 05:05:13 字数 212 浏览 0 评论 0原文

在 C# 中,我总是使用 PascalCase 表示属性(最佳实践,对吗?),对于数据库,我总是使用小写字母表示表和列名(最佳实践,对吗?)

当我使用实体框架从表生成类时,我在 C# 中得到小写属性名称,所以我在 C# 中手动重构了这个案例。

我想知道,当数据库的目的是为使用实体框架的 C# 应用程序提供支持时,在数据库中使用 PascalCase 表名和列名是否是最佳实践?

In C# I always use PascalCase for properties (best practice, right?), for databases i always use lowercase for tables and columnnames (best practice, right?)

When I generate classes from tables using entity framework, i get lowercase property names in C#, so I manually refactor the case in C#.

I wondered, is it best practice to use PascalCase table names and column names in the database, when the purpose of the database is to provide backing for a C# application that uses entity framework ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

千里故人稀 2024-10-02 05:05:13

您认为 Pascal 大小写适合 C# 属性是正确的,但是我不同意您关于小写大小写是数据库最佳实践的评论。我一直认为帕斯卡大小写是表名和列结构的最佳实践。 (无论如何,这是我在一份旧工作中被一位 DBA 告知的,而且它似乎与我工作过的其他地方一致。)

无论如何,如果您公司的编码/开发标准规定数据库的列名必须小写,并且表,那么你就必须这样做。您不应该编写专门用于实体框架的数据库。 EF 是一个 ORM,而不是数据库,因此数据库不应该关心它是如何访问的。

您应该设计数据库,遵守现有的任何规则,然后使实体框架重新映射这些列以正确的属性名称。通过模型编辑器可以非常轻松地完成此操作。

You're right about Pascal Casing being right for C# properties, however I would disagree with your comment about lower casing being best practise for databases. I always thought Pascal casing was the best practise in table names and column structure. (That's what I was told by a DBA at an old job anyway and it seems to be consistent with everywhere else I've worked.)

Anyway, if your company's coding/development standards say that the database must have lower case names for columns and tables, then you have to do it. You shouldn't write a database specifically for use with Entity Framework. EF is an ORM, not a database, so the database should not care about how it's accessed.

You should design the database, sticking to any rules you have in place, and then make Entity Framework remap those columns to correct property names. It's incredibly easy to do through the Model Editor.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文