EntityDataSource using IN clause on navigation property collection

1.6k views Asked by At

Hi I'm using EntityDataSource to retrieve my items, and i want to get the items for a particular region. (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. 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>  
1

There are 1 answers

1
Dimentox On

Typically using the in keyword is done as follows.

This is with MVC 3 and this is in the controller using 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);
        }