ASP.NET MVC 视图上的 DBNull 值
我正在编写一个简单的 ASP.NET MVC Web 应用程序。此时,我只是尝试在自动生成的视图上显示强类型数据集。但是,DataSet 中的某些值为 null 并会导致异常。
我想知道其他人如何处理这个简单的场景。清理数据集中的所有值似乎太过分了,而且我最终会在最终产品中得到很多数据集。我使用数据集是因为我有一个 Oracle 后端,因此实体模型有点过时了 - 我宁愿不使用示例提供程序或为商业解决方案花钱。
如果数据集没有简单的解决方案,那也没关系。我只是想在进行一些严肃的定制之前检查一下。我想让事情尽可能自动化和传统。
提前致谢。
I am writing a simple ASP.NET MVC web app. At this point, I am just trying to display a strongly typed DataSet on the automatically generated view. However, some of the values in the DataSet are null and cause exceptions.
I am wondering how this simple scenario is handled by others. It seems excessive to sanitize all the values in the dataset and besides I am going to end up with a lot of datasets in the final product. I am using DataSets because I have an Oracle backend, so Entity models are kind of out - I'd rather not use sample providers or dish out money for a commercial solution.
If there is no easy solution for DataSets, that's fine. I just wanted to check before I plunge into some serious customization. I'd like to keep things as automated and conventional as possible.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这样做是否不可能:
您还可以将其转换为简单的扩展方法以节省空间和击键。
HTH,
查尔斯
Would it be out of the question to do something like:
You could also convert that into a simple extension method to save space and keystrokes.
HTHs,
Charles
如果您可以修改数据库,则可以使用合并函数来保证一些非空默认值:
或
If you can modify your db, you could use the coalesce function to guarantee some non-null default value:
or