查找表和枚举 [英] Lookup Tables and Enums

查看:68
本文介绍了查找表和枚举的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 我有一个包含许多类型为smallInt的列的表,它实际上是来自引用表的查找值。

 I have a table with lots of columns of type smallInt which are actually lookup values from referential tables.

 一种方法是使用实​​体框架中的枚举类型,并轻松更改这些字段的值。

 One approach is use to Enumeration type in the Entity Framework and easily change values of the those fields.

 然而这并不理想,因为这些基本上是硬编码的。

 However that is not ideal, since those are essentially hardcoded.

 我需要灵活性,因为这些查找表中的值及其顺序可能会随着时间的推移在数据库中发生变化。

 I require flexibility because the values in those lookup tables and their order might get changed in database over time.

 对此有什么解决方案吗?

 Any solution to this ?

Shahid Roofi

Shahid Roofi

推荐答案

嗨Shahid,

Hi Shahid,

>>任何解决方案?

以下文章提供了一个使用配置的解决方案.Seed()每次应用迁移时调用的方法。即使没有待定的迁移,也会调用它。

The following article provide a solution, which use Configuration.Seed() method that is called every time the migrations are applied. It is called even if there are no pending migrations.

https://coding.abel.nu/2013/11/enums-and-lookup-tables-with-ef-code-first/

注意:此响应包含对第三方万维网站点的引用。 Microsoft提供此信息是为了方便您。 

Note: This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. 

Microsoft不控制这些网站并且未测试任何网站在这些网站上找到的软件或信息;因此,Microsoft不能就任何
软件或信息的质量,安全性或适用性做出任何陈述。

Microsoft does not control these sites and has not tested any software or information found on these sites;Therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information
found there.

使用互联网上的任何软件都存在固有的危险,微软提醒您在检索之前确保完全理解风险来自互联网的软件。

There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.

祝你好运,

Cole Wu


这篇关于查找表和枚举的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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