is this feasible or a good idea?

  • Thread starter Thread starter Dan Holmes
  • Start date Start date
D

Dan Holmes

in a follow up to the thread "a better way for user searches" the
"search" method signature is this:
public List<ProductInfo> List(ProductInfo productInfo1, ProductInfo
productInfo2)

That produces problems in determining if the user is wanting to check
the column for nulls or doesn't want to include the column in the search
criteria.

What if i changed it to this?
public List<ProductInfo> List(System.CodeDom.CodeExpression expression)

based on what the user chooses on the expression is built (with all the
"and"s and "or"s). I would use reflection on ProductInfo to determine
the property names.

It is then turned into SQL and executed. This app n-tier and remoting
is involved if that matters.

Is this a good idea? Anyone tried this?

dan
 
Dan,

Why not just use the Expression class instead? It would make it much
easier to construct these expressions, and you would more likely than not be
able to use it with LINQ to SQL to have it generate the query for you.
 
Nicholas said:
Dan,

Why not just use the Expression class instead? It would make it much
easier to construct these expressions, and you would more likely than not be
able to use it with LINQ to SQL to have it generate the query for you.

pardon my ignorance but what namespace does that live in? Do i need
vs2008 for it?

dan
 
Marc said:
For a more complete discussion of building dynamic LINQ queries, see:

http://groups.google.com/group/micr...read/thread/76353240ec0652c3/4e2cc66c3d39ee9f
(note it spans a few pages)

Marc

I installed vs2008 and read the above thread a zillion times. I have
something that works and that i can expand. What i can't find is how to
test for nulls and a like operator.

The other thing i couldn't figure is how the query turns into SQL. I
found this in the thread

string sql = db.GetCommand(paged).CommandText;

Where did db come from? i created a tableadapter and a dataset for my
products table but i couldn't find a GetCommand() on any of the objects.

I don't necessarialy need the whole statemnt; i only need the where
clause. The ToString() of the BinaryExpression produced a decent SQL
clause.

dan
 
Where did db come from?

Ah; LINQ-to-SQL is a new alternative data model; broadly comparable to
DataTable etc, but with a lot of new possibilities - such as
composable queries (which is what we are talking about here).

If you are working on an established project, this may not be
realistic; but for green-field work, you use LINQ-to-SQL by adding a
"LINQ to SQL classes" item to the project, and then dragging the
tables (from the server explorer) onto the designer surface (similar
to how you might design a DataSet)

(or you can use "sqlmetal"; or hand-craft the dbml file)

The "db" here is an instance of the DataContext, i.e. the main class
that represents your data model.

There are better explanations of LINQ to SQL on the intenet ;-p

Marc
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top