有谁知道如何在 linq 中重现 NVL() 函数

发布于 2024-10-30 05:39:48 字数 143 浏览 0 评论 0原文

所以我需要在需要一堆 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 技术交流群。

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

发布评论

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

评论(2

云裳 2024-11-06 05:39:48

您可以使用 null 合并运算符 ??

var abs = from row in table
          select new {a = row.a ?? "default", b = row.b};

该运算符查看左侧的值,如果为 null,则使用右侧的值。因此,在示例中,如果 row.a 为 null,则 a 变为 "default"

这假设 row.a 是一个字符串。

You can use the null coalescing operator ??:

var abs = from row in table
          select new {a = row.a ?? "default", b = row.b};

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, then a becomes "default".

This assumes that row.a is a string.

在你怀里撒娇 2024-11-06 05:39:48

如果有人想知道我最终是如何做到这一点的,我没有使用空合并运算符......它甚至比那更简单。也许我没有清楚地解释自己,但我需要做的是说,如果该值为空,则意味着我想包含该结果。一探究竟。

 possibleVendors = (from vndMapping in db.COMPANIES_VND_MAPPINGS
                     join v in db.COMPANIES_CMP_COMPANIES on vndMapping.VENDOR_ID equals v.COMPANY_ID
                     where
                     !(from ex in db.COMPANIES_VND_MAPPINGS
                        where (ex.OEM_ID == oemId || ex.OEM_ID == null)
                        && (ex.MODEL_ID == modelId || ex.MODEL_ID == null)
                        && (ex.MODALITY_ID == modalityId || ex.MODALITY_ID == null)
                        && (ex.CLASS_ID == productTypeId || ex.CLASS_ID == null)
                        && ex.EXCLUDE.ToUpper().Equals("Y")
                        select ex.VENDOR_ID).Contains(vndMapping.VENDOR_ID)
                     && (vndMapping.OEM_ID == oemId || vndMapping.OEM_ID == null)
                     && (vndMapping.MODEL_ID == modelId || vndMapping.MODEL_ID == null)
                     && (vndMapping.MODALITY_ID == modalityId || vndMapping.MODALITY_ID == null)
                     && (vndMapping.CLASS_ID == productTypeId || vndMapping.CLASS_ID == null)
                     select new
                     {
                       vndMapping.VENDOR_ID,
                       v.COMPANY_NAME
                     }).Distinct().OrderBy(x => x.VENDOR_ID).ToDictionary(x => x.VENDOR_ID, x => x.COMPANY_NAME);

现在请记住 - 我有一些限制,因为我没有设计业务逻辑(显然)或数据库 - 如果你完全控制一切,其他人可能有更好的方法来做到这一点,但这似乎可行。

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.

 possibleVendors = (from vndMapping in db.COMPANIES_VND_MAPPINGS
                     join v in db.COMPANIES_CMP_COMPANIES on vndMapping.VENDOR_ID equals v.COMPANY_ID
                     where
                     !(from ex in db.COMPANIES_VND_MAPPINGS
                        where (ex.OEM_ID == oemId || ex.OEM_ID == null)
                        && (ex.MODEL_ID == modelId || ex.MODEL_ID == null)
                        && (ex.MODALITY_ID == modalityId || ex.MODALITY_ID == null)
                        && (ex.CLASS_ID == productTypeId || ex.CLASS_ID == null)
                        && ex.EXCLUDE.ToUpper().Equals("Y")
                        select ex.VENDOR_ID).Contains(vndMapping.VENDOR_ID)
                     && (vndMapping.OEM_ID == oemId || vndMapping.OEM_ID == null)
                     && (vndMapping.MODEL_ID == modelId || vndMapping.MODEL_ID == null)
                     && (vndMapping.MODALITY_ID == modalityId || vndMapping.MODALITY_ID == null)
                     && (vndMapping.CLASS_ID == productTypeId || vndMapping.CLASS_ID == null)
                     select new
                     {
                       vndMapping.VENDOR_ID,
                       v.COMPANY_NAME
                     }).Distinct().OrderBy(x => x.VENDOR_ID).ToDictionary(x => x.VENDOR_ID, x => x.COMPANY_NAME);

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.

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