btw, if you're doing that, you may as well use the Where() syntax too:
var query = Default.Db.Klients.Where(b=>b.Region=="xx");
also:
// this causes exception: var cnt = orderedQueryable.Count();
You should log this as a bug with the DbLinq author/authors - it
should work.
Marc
Marc,
> var query = from b in Default.Db.Klients where
> region =="xx"
[quoted text clipped - 5 lines]
> // ...
> }
Thank you.
I need to pass those queries from my generic WinForms form constructor to
generic paged data retriever class.
I tried the following code but got error shown in comment. How to fix ?
class VirtualGridForm<T>: Form {
publicVirtualGridForm() {
IOrderedQueryable<T> orderedQueryable;
IQueryable<T> queryable;
switch ( typeof(T).Name ) {
case "Klient":
queryable = (IQueryable<T>)(from b in Default.Db.Klients select b);
//Error: 'T' does not contain a definition for 'Kood' and no extension
method 'Kood' accepting a first argument
// of type 'T' could be found (are you missing a using directive or an
assembly reference?)
orderedQueryable = queryable.OrderBy(b => b.Kood).ThenBy(b=>b.Tanav);
break;
case "Strings":
// this is ok but where clause needs to be duplicated if present.
queryable = (IOrderedQueryable<T>)(from b in Default.Db.Strings select b);
orderedQueryable = (IOrderedQueryable<T>)(from b in Default.Db.Strings
orderby b.Est
select b);
break;
default:
throw new ApplicationException("No query for table");
}
DataRetriever<T> DataRetriever = new DataRetriever<T>( queryable,
orderedQueryable);
}}
/// data retriever class based on MSDN Virtual DataGridView sample.
class DataRetriever<T> : IDataPageRetriever<T> {
IQueryable<T> Queryable;
IOrderedQueryable<T> OrderedQueryable;
internal DataRetriever(IQueryable<T> queryable,
IOrderedQueryable<T> orderedQueryable) {
Queryable = queryable;
OrderedQueryable = orderedQueryable;
}
public IList<T> SupplyPageOfData(int lowerPageBoundary, int rowsPerPage) {
return OrderedQueryable.Skip(lowerPageBoundary).Take(rowsPerPage).ToList();
}}
Btw. in ADO .NET I can simply use
DataRetriever<T> DataRetriever = new DataRetriever<T>( "SELECT * FROM
Klient" ,
" ORDER BY Kood, Tanav" );
Marc Gravell - 13 Jan 2008 15:13 GMT
> I tried the following code but got error shown in comment. How to fix ?
Well, I could build the property-access as an Expression, but IIRC
DbLinq had problems with that before (with dynamic Where clauses).
Compile-time LINQ (i.e. using the MethodInfo etc form) doesn't play
well with generic methods simply on "T" since you can't really do much
with a lambda just on "T", and DbLinq didn't (last time we chacked)
get on well with the Expression form, even though LINQ-to-SQL was
perfectly happy...
I wonder if something a bit more like a factory would be a better
approach here - i.e. in the switch calling out to your specific (fully
typed) methods to build the query/queries... it would need a little
casting, but much less pain than string-based expressions... just a
thought...
Marc