How to Select and Sort

Posts   
 
    
cmprogrock
User
Posts: 40
Joined: 16-Nov-2008
# Posted on: 19-Jun-2009 17:50:31   

I want to do something dead simple. I want to ... Select "PageEntities" Where AppID = 2 AND IsActive=True , OrderBy NavOrder

Seems simple.

I am using Adapter. I am using C#. I do not want to return every PageEntity in the DB - then filter & sort it in memory. I want SQL Server to Filter & Sort it and send me back just what i want.

Can someone please just post an example that will do this?

(I'm 30 pages into verbose documentation and still confused on the matter )

Thanks CM

Posts: 112
Joined: 09-Aug-2004
# Posted on: 19-Jun-2009 22:18:09   


IRelationPredicateBucket bucket = new RelationPredicateBucket(PageEntiityFields.AppID == 2 & PageEntityFields.IsActive == true);

ISortExpression sort = new SortExpression(PageEntiityFields.NavOrder| SortOperator.Descending)

EntityCollection<PageEntities> entities = new EntityCollection<PageEntities>();

adapter.FetchEntityCollection(entites, bucket, 0, sort, null)


I think that code should be correct, I may have a few syntax errors. That will do all the filtering/sorting in sql. When ever I want to know what it is doing in sql, I usually enable tracing through the config file.


  <system.diagnostics>
    <switches>
      <add name="SqlServerDQE" value="4"/>
    </switches>
  </system.diagnostics>

Keep working your way through the documentation, it has got all the information!