简体   繁体   English

在导航属性集合上使用IN子句的EntityDataSource

[英]EntityDataSource using IN clause on navigation property collection

Hi I'm using EntityDataSource to retrieve my items, and i want to get the items for a particular region. 嗨,我正在使用EntityDataSource检索我的物品,我想获取特定区域的物品。 (items and regions has a many to many relationship, thus item has a regions navigation property). (项目和区域具有多对多关系,因此项目具有区域导航属性)。 and I'm using "IN" to filter the items. 并且我使用“ IN”来过滤项目。 tried several combinations and it kept on throwing various errors. 尝试了几种组合,并不断抛出各种错误。 how can i get this sorted out: 我怎样才能解决这个问题:

Below is My DataSource: 以下是我的数据源:

<asp:EntityDataSource ID="CataloguesDataSource" runat="server" ConnectionString="name=ModelContainer" 
    DefaultContainerName="ModelContainer" EnableInsert="false" EnableUpdate="false"  OrderBy="it.EndDate desc,it.id desc" Include="it.Regions"
    EntitySetName="Catalogues"   Select="it.Id,it.Name,it.StartDate,it.EndDate,it.RetailerId"
    Where="it.Retailer.Name=@RetailerName and @Region IN (select p.Id from it.Regions as p)" >
   <WhereParameters> 
        <asp:ControlParameter Name="RetailerName" ControlID="hdnRetailer" DbType="String"  PropertyName="Value" DefaultValue="abc"  />
        <asp:ControlParameter Name="Region" ControlID="hdnregion" DbType="Int32"  PropertyName="Value" DefaultValue=""  />      

     </WhereParameters>
</asp:EntityDataSource>  

Typically using the in keyword is done as follows. 通常,使用in关键字的操作如下。

This is with MVC 3 and this is in the controller using Entity framework. 这与MVC 3一起使用,并且在使用Entity Framework的控制器中。


public ActionResult Index()
        {
            myEntities context = new myEntities();

            var result = from o in context.entitya
                         where o.somecolumn != "blahh"
                         select new
                         {
                             id = o.id,
                             name = o.name
                         };

            return Json(new { data = result, total = result.count() }, JsonRequestBehavior.AllowGet);
        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM