Thursday, 15 July 2010

c# - Execute expression on another IQueryable source -



c# - Execute expression on another IQueryable source -

there 2 classes identical field structure: webmessage , webmessagedto.

i have datagrid can work both classes. , have ria service can provide webmessagedto because webmessage has navigation properties , cannot serialized.

now, datagrid should query ria service method returning iqueryable<webmessagedto>. need handle datagrid's query , execute on orm's table<webmessage>, transform result webmessagedto type , homecoming datagrid.

i started implement custom iqueryable interface , can handle expression.

public class webmessagequerycontext { // executes look tree passed it. internal static object execute(expression expression, bool isenumerable) { // datacontext.webmessages orm table returns iqueryable<webmessage> list<webmessage> list = datacontext.webmessages.provider.execute(expression); homecoming webmessagedto.convertfrom(list); // returning list<webmessagedto> } }

the code above create recursive calls method. , found microsoft's sample queryable source changes in expressionvisitor , alter original source orm's table.

protected override look visitconstant(constantexpression c) { if (c.type == typeof(webmessagedtoquerysource<webmessagedto>)) homecoming expression.constant(datacontext.webmessages); homecoming c; }

i'm getting exception when execute expression:

expression of type 'system.data.linq.table'1[webmessage]' cannot used parameter of type 'system.linq.iqueryable'1[webmessagedto]' of method 'int32 count[webmessagedto](system.linq.iqueryable1[webmessagedto])'`

there's no much info iqueryableproviders , don't know do... can answer, can theoretically?

sorry guys, wrong. before question edit wrote select applied iqueryable before where causes loading table rows in memory , executing where statement. such behavior caused wrong implementation of custom linq provider.

when used datagrid without custom linq provider mentioned select executes after where when select applied before where.

in code:

public iqueryable<webmessagedto> dtos { { homecoming db.webmessages.select(r => new webmessagedto { id = r.id });} }

my datagrid queries method where/orderby/groupby statements , conversion webmessagedto occurs after them.

so, alex key's reply applicable.

c# linq iqueryable

No comments:

Post a Comment