有谁知道如何在 linq 中重现 NVL() 函数
所以我需要在需要一堆 NVL 的地方进行查询,但我需要在 linq 中执行这些操作(如果它有帮助的话,数据库后端是 BD2 并且我们正在使用亚音速)我在网上搜索了“NVL linq”,但没有真的发现任何有用的东西,所以我在这里问,
谢谢你的帮助......
So I need to do a query where I need a bunch of NVL's but I need to do these in linq (if it helps the db backend is BD2 and we are using subsonic) I searched the web for "NVL linq" and didn't really find anything useful so I am asking here,
Thanks for your help...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用 null 合并运算符
??
:该运算符查看左侧的值,如果为 null,则使用右侧的值。因此,在示例中,如果
row.a
为 null,则a
变为"default"
。这假设
row.a
是一个字符串。You can use the null coalescing operator
??
:The operator looks at the value on the left and if it is null then it uses the value on the right. So in the example if
row.a
is null, thena
becomes"default"
.This assumes that
row.a
is a string.如果有人想知道我最终是如何做到这一点的,我没有使用空合并运算符......它甚至比那更简单。也许我没有清楚地解释自己,但我需要做的是说,如果该值为空,则意味着我想包含该结果。一探究竟。
现在请记住 - 我有一些限制,因为我没有设计业务逻辑(显然)或数据库 - 如果你完全控制一切,其他人可能有更好的方法来做到这一点,但这似乎可行。
If anyone wants to know how I ended up doing this I didn't use the null coalesce operator... It was even simpler than that. Maybe I didn't explain my self clearly but what I needed to do was to say that if the value is null then means I want to include that result. Check it out.
Now keep in mind - I had a few limitations in that I didn't design the business logic (obviously) or the database - Someone else might have a better way to do this if you had complete control of everything, this seems to work though.