LinqDataSource 中的参数

发布于 2024-11-06 07:19:04 字数 942 浏览 0 评论 0原文

我有 2 个表:

carType:
==
id
CarTypeTitle

正如

Items
==
id
ItemTitle
CarTypeId1
CarTypeId2
CarTypeId3

您所看到的,我在 CarTypeId(来自 Items 表)与 id(CarType 表)之间建立了关系,以及 CarTypeId2(来自 Items 表)与 id(CarType 表)之间的关系...等等。

我有 2 个下拉列表,ddl1,ddl2。 ddl1 用于汽车类型,ddl2 用于物品。我成功地进行了级联,这与 ddl2 的 WHERE 参数配合得很好:

<asp:LinqDataSource ID="LinqDataSource4" runat="server" ContextTypeName="DataClassesDataContext" EntityTypeName="" TableName="Items" Where="CarTypeId1 == @CarTypeId1">
    <WhereParameters>
        <asp:ControlParameter ControlID="ddl2" Name="CarTypeId" PropertyName="SelectedValue" Type="Int32" />
    </WhereParameters>
</asp:LinqDataSource>

当我选择 cartype 时,ddl2 给我按照 cartypeid1 的项目。但是我如何编写代码(WHERE参数)来给我type2和3。

我有一些与相同车型相关的项目,即:Wiper-bla与subaro和fiat相关...所以我给他们subaro 和 fiat 的 cartypeid...

希望一切都清楚。

I have 2 tables:

carType:
==
id
CarTypeTitle

and

Items
==
id
ItemTitle
CarTypeId1
CarTypeId2
CarTypeId3

as you can see, i made relationship between CarTypeId (from Items table) to id (CarType Table), and relatshionship between CarTypeId2 (from Items table) to id (CarType table)... and so on.

i have 2 dropdownlist, ddl1, ddl2. ddl1 for carTypes, and ddl2 for items. i succeed with the cascading and that's work great with WHERE parameter at ddl2:

<asp:LinqDataSource ID="LinqDataSource4" runat="server" ContextTypeName="DataClassesDataContext" EntityTypeName="" TableName="Items" Where="CarTypeId1 == @CarTypeId1">
    <WhereParameters>
        <asp:ControlParameter ControlID="ddl2" Name="CarTypeId" PropertyName="SelectedValue" Type="Int32" />
    </WhereParameters>
</asp:LinqDataSource>

when i choose cartype the ddl2 give me In accordance the item for cartypeid1. but how i write the code (WHERE parameter) that will give me the type2 and 3.

i have some items that related to the same cartype, i.e: Wiper-bla is related to subaro and to fiat... so i give them the cartypeid of subaro and fiat...

hope that's all is clear.

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

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

发布评论

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

评论(1

强辩 2024-11-13 07:19:04

这是您要找的吗?

<asp:LinqDataSource ID="LinqDataSource4" runat="server" ContextTypeName="DataClassesDataContext" EntityTypeName="" TableName="Items" Where="CarTypeId1 == @CarTypeId OR CarTypeId2 == @CarTypeId OR CarTypeId3 == @CarTypeId">
    <WhereParameters>
        <asp:ControlParameter ControlID="ddl2" Name="CarTypeId" PropertyName="SelectedValue" Type="Int32" />
    </WhereParameters>
</asp:LinqDataSource>

不过,我强烈建议更新您的数据模型以使用单独的表来连接 CarType 和 Items。例如,

ItemToCarType
=============
ItemId
CarTypeId

通过此表,您可以为每个项目包含无限数量的 CarType。而且您将简化查询,因为您不需要单独处理每个字段(就像在本例中使用 OR

Is this what you are looking for?

<asp:LinqDataSource ID="LinqDataSource4" runat="server" ContextTypeName="DataClassesDataContext" EntityTypeName="" TableName="Items" Where="CarTypeId1 == @CarTypeId OR CarTypeId2 == @CarTypeId OR CarTypeId3 == @CarTypeId">
    <WhereParameters>
        <asp:ControlParameter ControlID="ddl2" Name="CarTypeId" PropertyName="SelectedValue" Type="Int32" />
    </WhereParameters>
</asp:LinqDataSource>

However I would strongly suggest updating your data model to use a separate table to connect CarTypes and Items. e.g.

ItemToCarType
=============
ItemId
CarTypeId

With this table you can include an unlimited number of CarTypes for each item. And you will simplify your queries, because you don't need to handle every field separatly (like using OR in this example)

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