Last post Sep 07, 2011 10:53 PM by pizzamaker74
Sep 06, 2011 04:15 AM|pizzamaker74|LINK
There are two tables
Table1 - Contains the columns I want to return
Table2 - Has a foreign key to Table1
- Has a column I need to filter Table1 records on
I want to join on the foreign key and then filter on Table2 to return records from Table1
I want to use Dynamic Data to do this.
I have done so easily with one table, but not sure on how to do so with two.
I'm using Linq to SQL for my DataContext.
I'm not sure how to do this. I really like the way Dynamic Data sorts out my paging and controls, so would prefer if I could continue to do it this way.
Does anyone have any ideas? -
I really want to continue using Dynamic Data for this.
Do I need to use Stored Procedures or is there some other way?
I know I can solve the query with Linq to SQL but I don't know how I can then include this in the Dynamic data.
See Linq Query below for query.
MainDataContext tDC = new MainDataContext();
IEnumerable results = from o in tDC.Table1
from a in tDC.Table2
where a.filterfield == "FilterText"
If anyone has any good examples of what I'm trying to do I'd appreciate greatly.
Sep 06, 2011 06:38 AM|sjnaughton|LINK
Sadly that is the only way with the current version of DD you will need to add a custom expression to the QueryExtender like this
<asp:QueryExtender TargetControlID="GridDataSource" ID="GridQueryExtender" runat="server">
<asp:DynamicFilterExpression ControlID="FilterRepeater" />
<asp:CustomExpression OnQuerying="Filter" />
protected void Filter(object sender, CustomExpressionEventArgs e)
e.Query = from c in e.Query.Cast<Customer>()
where c.Location.Name == "Name"
as an example.
Sep 07, 2011 10:53 PM|pizzamaker74|LINK
I had trouble getting it to work though, and ended up using a stored proc and linq in codebehind due to time constraints.
Will have to re-look at this later. I was close.
Mark it as answer if you're happy it works.