实体 Famework 中的 where in 子句

发布于 2024-12-23 04:19:45 字数 880 浏览 4 评论 0原文

我需要编写一个带有“where in”子句的查询。我正在使用实体框架 4。

我的 sql 查询是:

select ITEMNMBR, locncode, qtyonhnd, atyalloc 
from dbo.iv00102 
where ITEMNMBR IN (
                   SELECT  cmptitnm 
                   from dbo.bm00111
                   where itemnmbr == bomItem)
AND LOCNCODE = 'MEMPHIS'

需要这样的查询:

public static Func<DBEntities, string, IQueryable<IV00102>> compiledMemphisQuery =
        CompiledQuery.Compile((DBEntities ctx, string bomNumber) =>
            from items in ctx.IV00102
            where   items.ITEMNMBR in (
                                        from orders in ctx.bm00111
                                        where orders.itemnmbr == bomItem
                                        select orders.cmpitnm)
            and items.locncode == "Memphis"
            select items);

I have a requirment to write a query with "where in" clause. I am using entity framework 4.

My sql query is:

select ITEMNMBR, locncode, qtyonhnd, atyalloc 
from dbo.iv00102 
where ITEMNMBR IN (
                   SELECT  cmptitnm 
                   from dbo.bm00111
                   where itemnmbr == bomItem)
AND LOCNCODE = 'MEMPHIS'

Need a query somthing like this:

public static Func<DBEntities, string, IQueryable<IV00102>> compiledMemphisQuery =
        CompiledQuery.Compile((DBEntities ctx, string bomNumber) =>
            from items in ctx.IV00102
            where   items.ITEMNMBR in (
                                        from orders in ctx.bm00111
                                        where orders.itemnmbr == bomItem
                                        select orders.cmpitnm)
            and items.locncode == "Memphis"
            select items);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

风吹雪碎 2024-12-30 04:19:45

使用查询的 Contains 扩展方法。它应该有效:

public static Func<DBEntities, string, IQueryable<IV00102>> compiledMemphisQuery =
    CompiledQuery.Compile((DBEntities ctx, string bomNumber) =>
        from items in ctx.IV00102
        where   (
                                    from orders in ctx.bm00111
                                    where orders.itemnmbr == bomItem
                                    select orders.cmpitnm)
        and items.locncode == "Memphis"
        select items).Contains(items.ITEMNMBR);

Use the Contains extension method of the query. It should work:

public static Func<DBEntities, string, IQueryable<IV00102>> compiledMemphisQuery =
    CompiledQuery.Compile((DBEntities ctx, string bomNumber) =>
        from items in ctx.IV00102
        where   (
                                    from orders in ctx.bm00111
                                    where orders.itemnmbr == bomItem
                                    select orders.cmpitnm)
        and items.locncode == "Memphis"
        select items).Contains(items.ITEMNMBR);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文