在C#代码中检索参考数据 [英] Retrieving Reference Data in C# Code

查看:51
本文介绍了在C#代码中检索参考数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在SQL中有一个参考数据表,其中包含此SCHEMA

I have a reference data tables in SQL with this SCHEMA

StatusId(主键)

StatusId (Primary Key)

StatusType(唯一)

StatusType (Unique)

StatusDescription

StatusDescription

StatusCode(唯一)

StatusCode (Unique)

在使用LINQ的代码中,我使用StatusCode列查询此表。我想将StatusCode值保存在一个地方,而不是在我查询它的地方进行硬编码。

In my code using LINQ, I query this table using the StatusCode column. I want to keep the StatusCode values in one place rather then hard coding it where ever I am querying for it.

如何去做?

感谢您的帮助。




推荐答案

你好,

答案可以分为几个方向,具体取决于你在哪里进行数据操作例如,在一种形式中,以多种形式,在数据类中。这些编码需要在哪里进行最后一个如何编写当前数据操作的声明。

The answer can go in several directions dependent on where you have data operations in e.g. in a form, in several forms, in a data classes for instance. Where are these coded needed going with the last statement of how you have written current data operations.

如果您正在编写专业编码,那么您将拥有一个数据类,该数据类将有一种获取代码的方法一旦他们不改变,例如。加载数据一次(再次取决于您当前使用数据的方法)或根据需要。

If you are coding professionally you will have a data class which would have a method to obtain the codes once if they don't change for instance. Load the data once (again it depends on your current method of working with data) or as needed.

另一件需要考虑的事情是,当检索数据时,表中存储了多少行快速。

Another thing to consider is how many rows are stored in the table, when retrieving data is t quick.

不要挂在LINQ上,这不是每个解决方案的答案。替代方案包括将数据存储在具体类别的列表中,该列表比其他选项重量轻。通过连接,命令和读取器通过while
循环获取数据。

Don't get hung up on LINQ, it's not the answer to every solution. Alternates include storing the data in a list of a concrete class which is much light weight that other options. Get the data via a connection, command and a reader off the command via a while loop.


这篇关于在C#代码中检索参考数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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