Re: Linq Entity question regarding Where clause
If I understand your question, you want to create a generic implementation
of a LINQ search that a person can append any number of an object's fields
to and have that object, or objects, selected back.
If you are asking "can this be done out of the box", the answer is no. If
you are asking "can this be coded", I would say sure. One way I can think of
is to dynamically create the
where order.OrderQty > 2 && order.OrderQty < 6
from your search class. One way to do this is to iterate through the
properties set on a LINQ object (ints that are not 0 and strings that are
not null) and dynamically create a query. You would then create a
Func<TSource, bool> expression and use that to query LINQ. You can get
rather complex here. The one part of the puzzle I have not explored is how
to create this expression, but I would look at going from string to
expression, if that is possible.
There is probably another way to tackle this problem. I just cannot think of
it presently.
--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA
Subscribe to my blog
http://feeds.feedburner.com/GregoryBeamer#
or just read it:
http://feeds.feedburner.com/GregoryBeamer
********************************************
| Think outside the box! |
********************************************
"Ben" wrote in message
news:8467980b-7cd0-49d2-bc1b-36121ab3f04e@b30g2000prf.googlegroups.com...
> Hi, Thanks for reading the post. I would like to pass a search Entity
> (for instance a "WorkerSearchEntity" that has several properties a
> user can search on. Not necessarily all "search" properties will be
> searched against. My question, is there a way to create a Linq to
> Entity or Linq to SQL that will accept this "search" entity without
> having to do something like below?
>
> var query =
> from order in orders
> where order.OrderQty > 2 && order.OrderQty < 6 // don't want
> to do this!
>
> Would prefer something that I don't have to iterate through the entity
> to determine which properties are not null... such as.. psuedocode...
>
> where order = OrderSearchEntity;
>
> Hoping that the code generator would handle the items such as...
>
> where order.orderNumber = OrderSearchEntity.OrderNumber &&
> order.orderDate = OrderSearchEntity.OrderDate
>
> I appreciate any help on this. Thanks
date: Fri, 22 Aug 2008 08:24:38 -0500
author: Cowboy \(Gregory A. Beamer\) oSpamM