Linq 到 Sql 多对多

发布于 2024-12-26 07:43:16 字数 641 浏览 4 评论 0 原文

我在 Linq-to-SQL 中遇到多对多查询问题。

我有一个名为 user 的表。

用户已获得 2 个产品 >加入product.UserID Product 可以有 2 件装备。 ProductEquipments 具有多对多关联

我想获取用户的设备:

 var match =  from c in ctx.Products                              
    where c.UserID == USERID
    select c.Equipments;

此代码返回 IQueryable> ; 类型对象。

但我想获得 IQueryable 类型对象。我该如何施放?

I have a many-to-many query problem in Linq-to-SQL.

I have a table named user.

User has got 2 products > join product.UserID
and Product can be have 2 equipment. Product to Equipments have many to many association

I want to get user's equipments:

 var match =  from c in ctx.Products                              
    where c.UserID == USERID
    select c.Equipments;

This code returns IQueryable<System.Data.Objects.DataClasses.EntityCollection<Equipments>> typed object.

But I want to get IQueryable<Equipments> typed object. How can I cast?

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

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

发布评论

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

评论(1

梦开始←不甜 2025-01-02 07:43:16

听起来您想要SelectMany

var match =  from c in ctx.Products                              
    where c.UserID == USERID
    from e in c.Equipments
    select e;

match 现在是 IQueryable

It sound like you want SelectMany.

var match =  from c in ctx.Products                              
    where c.UserID == USERID
    from e in c.Equipments
    select e;

match is IQueryable<Equipments> now

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