ASP.NET MVC 视图上的 DBNull 值

发布于 2024-08-31 07:04:41 字数 301 浏览 1 评论 0原文

我正在编写一个简单的 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 技术交流群。

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

发布评论

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

评论(2

晨光如昨 2024-09-07 07:04:41

这样做是否不可能:

<%= (eventClass["MyColumn"] != DBNull.Value) ? eventClass["MyColumn"] : "" %>

您还可以将其转换为简单的扩展方法以节省空间和击键。

HTH,
查尔斯

Would it be out of the question to do something like:

<%= (eventClass["MyColumn"] != DBNull.Value) ? eventClass["MyColumn"] : "" %>

You could also convert that into a simple extension method to save space and keystrokes.

HTHs,
Charles

够钟 2024-09-07 07:04:41

如果您可以修改数据库,则可以使用合并函数来保证一些非空默认值:

select coalesce(first_name, '') as first_name, ...

select coalesce(parent_id, 0) as parent_id, ...

If you can modify your db, you could use the coalesce function to guarantee some non-null default value:

select coalesce(first_name, '') as first_name, ...

or

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