2011-05-10 42 views
0

参数我有2个表:凡的LinqDataSource

carType: 
== 
id 
CarTypeTitle 

Items 
== 
id 
ItemTitle 
CarTypeId1 
CarTypeId2 
CarTypeId3 

,你可以看到,我做了CarTypeId之间的ID(CarType表)的关系(从项目表),并CarTypeId2(从Items表)到id(CarType表)...之间的relatshionship ...等等。

我有2 dropdownlist,ddl1,ddl2。 ddl1代表carTypes,ddl2代表物品。我与级联取得成功,这是工作的伟大与WHERE参数在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> 

当我选择cartype的DDL2给我按照该项目的cartypeid1。但我怎么写代码(WHERE参数),这将给我的类型2和3.

我有一些项目涉及到相同的cartype,即:刮水器bla是关系到subaro和法定...所以我给他们subaro和fiat cartypeid ...

希望这一切都很清楚。

回答

1

这是你在找什么?

<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> 

但是,我强烈建议更新您的数据模型,使用单独的表来连接CarTypes和Items。例如

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

使用此表,您可以为每个项目包含无限数量的CarType。而且你会简化你的查询,因为你不需要分开处理每个字段(例如在本例中使用OR

+0

使用OR是我寻找的。我问了很多次这个问题,一无所获,你的回答非常好!非常感谢 ! – Oshrib 2011-05-10 09:58:22