拉入动态 DBF 列
我被要求拉入列以在网络应用程序中使用。我使用的是 asp.net 和 C#。 我使用 dataReader 来填充类变量。 问题是 dbf 文件可能会更改。 有时会添加或删除行,因此每次数据源文件更改以表示列时,我的类都必须更改有没有办法解决这个问题?
I have been asked to pull in columns for use in a web app.I am using asp.net and C#. I was using a dataReader to populate the class variables. The problem is that the dbf file can change. Sometimes rows are added or deleted so my class would have to change every time the data source file changes to represent the columns Is there a way around this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
解决这个问题的方法有很多,您的问题是由一整类称为对象关系映射或 ORM 的解决方案来处理的。 Java 和 .Net 世界中绝对的王者是 NHibernate。 这确实意味着每次数据库更改都会进行重建,我使用代码生成来解决该问题,直接从数据库构建类和映射文件。 然后你进入 TDD 和 CI,以确保你没有破坏任何东西,然后......
但是,如果你想要一些快速而肮脏的东西,你可以在你的类中创建一个字典并在其中存储任何额外的列。 完全灵活,但您的类额外列并未在类本身中定义。
Lots of ways of addressing this issue, your problem is handled by a whole class of solutions known as Object Relational Mapping or ORM. The absolute king of these in the Java and .Net world is NHibernate. This does nean a rebuild with each DB change though, I use code generation to solve that problem, builds the class and mapping files direct from the DB. Then you get into TDD and CI, to make sure you haven't broken anything and then .....
However, if you want something quick and dirty you could create a dictionary within your classes and store any extra columns in there. Completely flexible but your classes extra columns aren't defined within the class itself.
我只是使用了一些 try/catch 块来解决这个问题。
I just used a few try/catch blocks to solve this.