This is a migrated thread and some comments may be shown as answers.

Complex Search - Date Between, ListValue, Null etc.

3 Answers 107 Views
LINQ (LINQ specific questions)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Devanand Chahal
Top achievements
Rank 2
Devanand Chahal asked on 25 Aug 2009, 09:14 AM
Hello,
I am adding my method that i will use for adding search criteria:

 

public Collection<CaseTest> QuickSearchCaseTest(string pCaseTest, InvokeContext ctx)
{  

 

    // To Do : To Search the result based on the complex criteria. It is just for reference now  

 

    IObjectScope scope = CaseTestScopeProvider.GetNewObjectScope();  

 

 

    var result = from c in scope.Secure<MtCaseTest>()  

 

    where (c.CaseReference.ToUpper().Matches(pCaseTest) || c.ShortTitle.ToUpper().Matches(pCaseTest))  

 

    select c; 

 

 

    Collection<CaseTest> serviceResult = new Collection<CaseTest>();  

 

    using (CaseTestFacade<MtCaseTest, CaseTest> mapper = new CaseTestFacade<MtCaseTest,CaseTest>())  

    { 

 

        foreach (MtCaseTest org in result)  

        serviceResult.Add(mapper.GetContractObject(org));

    } 

 

    return serviceResult;  

}


Here pCaseTest parameter can be an xml file that will provide me the different fields for search criteria and what kind of search to do for particular field,  My CaseTest class have about 30 attributes, and i need to apply search filter for about 12 fields, and this search can vary based on the type of search for particular attribute, like
for date fields search can be :
[equal, does not equal, between, is not between, greater or equal, less or equal, within week, within month, within year],
For the fields that are multiselect in search criteria the search can be

 [equals, does not equal, starts with, does not start with,contains,does not contain, with, ends with, does not end with, is null, is not null, in the list, not in the list ].

For the fields that are free text the criteria can be :

 

[equals, does not equal, starts with, does not start with, contains, does not contain with, ends with, does not end with, is null , is not null]

Can you please suggest me how to perform such type for filtration while getting the records from database. And if there are some limitations to perform any of the search from above mentioned criteria's then please let me know that too.

Regards,
Dev Chahal

 

 

 

3 Answers, 1 is accepted

Sort by
0
Alexander
Telerik team
answered on 27 Aug 2009, 09:24 AM
Hello Devanand Chahal,

I am not sure if understand you correctly but you can use something like this:
IQueriable result = scope.Extent<PersistentObject>(); 
 
if( condition1 ) 
    result = result.Where( criteria1 ); 
 
if( condition2 ) 
    result = result.Where( criteria2 ); 
 
... 
Based on the field that you want to filter on and the type of comparison, you can append additional Where clause to the expression tree. At the end you can call result.ToList() to execute the query and retrieve the objects. Hope that helps.

All the best,
Alexander
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Devanand Chahal
Top achievements
Rank 2
answered on 07 Sep 2009, 09:58 AM
Hi Alexander,

its not working for me : 

I tried as u suggested me but now i m getting some other error:

public

 

Collection<CaseInvention> QuickSearchCaseInvention(string pCaseInvention, InvokeContext ctx)
{

 

 

 

    IObjectScope scope = CaseInvScopeProvider.GetNewObjectScope();

 

 

    var result = from c in scope.Secure<MtCaseInvention>()

 

 

    select c;

 

    result = result.Where(c => c.RejectionComment ==

"test Reject Comment");

 

 

    Collection<CaseInvention> serviceResult = new Collection<CaseInvention>();

 

 

    using (CaseInventionFacade<MtCaseInvention, CaseInvention> mapper =     new     CaseInventionFacade<MtCaseInvention,CaseInvention>())

 

    {

 

    foreach (MtCaseInvention org in result)

 

    serviceResult.Add(mapper.GetContractObject(org));

    }

 

    return serviceResult;

 

}

and when I m coming on the line " foreach (MtCaseInvention org in result)", getting following error:

"filtering non-extents not supported"

I had tried to change
"var result = from c in scope.Secure<MtCaseInvention>() "
to 
"var result = from c in scope.Extent<MtCaseInvention>() "

but stil getting same error.

I am using telerik's older version , its  "Telerik-OpenAccess-ORM-2008.03.1327.2". Is it due to older verion or some other reason for this error. Awaiting ur reply.

0
Alexander
Telerik team
answered on 09 Sep 2009, 09:07 AM
Hi Devanand Chahal,

It is very possible that the problem is caused by old version, we have improved significantly our Linq functionality during the last year. Please, notify us if you still get this error with the latest version.

Sincerely yours,
Alexander
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
LINQ (LINQ specific questions)
Asked by
Devanand Chahal
Top achievements
Rank 2
Answers by
Alexander
Telerik team
Devanand Chahal
Top achievements
Rank 2
Share this question
or