如何返回此查询值

发布于 2025-02-09 13:25:15 字数 721 浏览 2 评论 0原文

我将加入查询实现以加入两个表。如何返回这些值。

public List<cartItem> getcartItem(int userId)
    {


        var data = (from c in _context.cartItems join p in _context.Products
                    on c.productId equals p.ProId
                    where c.userId == userId && c.status==false select new {
                    proName=p.ProductName,
                    qty=c.quantity,
                    proImg=p.ImageUrl,
                    uPricce=p.price
                    }).ToList();

      
        return data;
       

    }

I implement the join query for join two tables. How to return those values.

public List<cartItem> getcartItem(int userId)
    {


        var data = (from c in _context.cartItems join p in _context.Products
                    on c.productId equals p.ProId
                    where c.userId == userId && c.status==false select new {
                    proName=p.ProductName,
                    qty=c.quantity,
                    proImg=p.ImageUrl,
                    uPricce=p.price
                    }).ToList();

      
        return data;
       

    }

enter image description here

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

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

发布评论

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

评论(1

情丝乱 2025-02-16 13:25:16

假设这些是Cartitem OBJ的属性,您只需要分配选择语句即可匹配返回类型和新的Cartitem。

...select new cartItem 
{
   proName = p.ProductName,
   qty = c.quantity,
   proImg = p.ImageUrl,
   uPricce = p.price
}).ToList();

Assuming these are the properties of a cartItem obj, you just need to assign the select statement to match the return type and new up a cartItem.

...select new cartItem 
{
   proName = p.ProductName,
   qty = c.quantity,
   proImg = p.ImageUrl,
   uPricce = p.price
}).ToList();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文