Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
DotNet
acad.assignment.mngr
academic
adonet
aspnet
aspnet.announcements
aspnet.build.controls
aspnet.caching
aspnet.datagridcontrol
aspnet.mobile
aspnet.security
aspnet.webcontrols
aspnet.webservices
clr
compactframework
component_services
datatools
distributed_apps
drawing
faqs
framework
framework.wmi
general
internationalization
interop
languages.csharp
languages.jscript
languages.vb
languages.vb.controls
languages.vb.data
languages.vb.upgrade
languages.vc
languages.vc.libraries
myservices
odbcnet
performance
remoting
scripting
sdk
security
setup
vjsharp
vsa
webservi.enhancements
webservices
windowsforms
windowsforms.controls
winforms.databinding
winforms.designtime
xml
  
 
date: Thu, 21 Aug 2008 22:27:31 -0700 (PDT),    group: microsoft.public.dotnet.framework        back       


Linq Entity question regarding Where clause   
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: Thu, 21 Aug 2008 22:27:31 -0700 (PDT)   author:   Ben

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

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us