Note that there are some explanatory texts on larger screens.

plurals
  1. POLINQ Outer Joins Dynamic OrderBy
    primarykey
    data
    text
    <p>In a Linq Statement like the following (narrowed down to relevant parts for the question):</p> <pre><code>var sites = from s in DataContext.Sites join add in DataContext.Address on s.PrimaryAddress equals add into sa from a in sa.DefaultIfEmpty() select new { s.Id, s.SiteName, PrimaryAddress = a }; </code></pre> <p>The problem we have is that a control ultimately based on a GridView/LinqDataSource combination cannot sort correctly on the PrimaryAddress joined class (ignores it). We see this same behavior for all joined classes like this. Is there any way for GridView to handle this? <strong>Or alternatively, is there a way via Expressions that we can handle it in code in a dynamic OrderBy?</strong></p> <p>Additional notes: When adding <code>.OrderBy(s =&gt; s.PrimaryAddress)</code> we get <code>Cannot order by type 'Address'</code>, when doing <code>.OrderBy(gs =&gt; gs.PrimaryBusinessAddress.AddressLine1)</code> we get <code>Specified method is not supported.</code> When doing the sort on the LinqDataSource.OrderBy itself, it's too late...it only sorts the records on the current page and not the overall set.</p> <p>For clarity, this is the format of the Address in the grid:</p> <pre><code>public partial class Address { public override string ToString() { return string.Format("{0} {1}{2} {3}", AddressLine1, City, !string.IsNullOrEmpty(State) &amp;&amp; State != "None" ? ", " + State : string.Empty, !string.IsNullOrEmpty(Country) ? string.Format("({0})", Country) : string.Empty); } } </code></pre> <p>If we could sort by <code>AddressLine1 + City + State + Country</code>, that would be good enough, but I'm unsure of how to do this via an expression tree...no matter what OrderBy we specify via expressions, it reverts to sorting by <strong>s.SiteName</strong> (the default sort on the grid). There are a very limited number of joined classes like this that show in our grid control, having an switch and Expression case for each would not be a problem at all. Any thoughts on a solution, or completely different approach?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload