Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
SieveModel Submodule Test
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nguyenvu
SieveModel Submodule Test
Commits
e83893c6
Commit
e83893c6
authored
Apr 03, 2020
by
thienvo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
optimize sieve
parent
7dbc4c69
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
53 additions
and
7 deletions
+53
-7
SieveProcessor.cs
Sieve/Services/SieveProcessor.cs
+53
-7
No files found.
Sieve/Services/SieveProcessor.cs
View file @
e83893c6
...
...
@@ -160,9 +160,10 @@ namespace Sieve.Services
}
public
Expression
<
Func
<
TEntity
,
bool
>>
GetFilterExpressionQuery
<
TEntity
>(
TSieveModel
model
,
TSieveModel
model
,
ref
string
dynamicQuery1
,
bool
bCaseSensitive
=
false
)
{
//string dynamicQuery = "";
if
(
model
?.
GetFiltersParsed
()
==
null
)
{
return
null
;
...
...
@@ -172,6 +173,7 @@ namespace Sieve.Services
var
parameterExpression
=
Expression
.
Parameter
(
typeof
(
TEntity
),
"e"
);
foreach
(
var
filterTerm
in
model
.
GetFiltersParsed
())
{
string
dynamicQuery
=
""
;
Expression
innerExpression
=
null
;
foreach
(
var
filterTermName
in
filterTerm
.
Names
)
{
...
...
@@ -181,6 +183,11 @@ namespace Sieve.Services
var
converter
=
TypeDescriptor
.
GetConverter
(
property
.
PropertyType
);
dynamic
propertyValue
=
parameterExpression
;
foreach
(
object
attrib
in
property
.
GetCustomAttributes
(
true
))
{
dynamicQuery
=
attrib
.
GetType
().
GetProperty
(
"StringValue"
).
GetValue
(
attrib
,
null
).
ToString
();
// Console.WriteLine(attrib);
}
foreach
(
var
part
in
fullName
.
Split
(
'.'
))
{
propertyValue
=
Expression
.
PropertyOrField
(
propertyValue
,
part
);
...
...
@@ -209,6 +216,8 @@ namespace Sieve.Services
.
First
(
m
=>
m
.
Name
==
"ToUpper"
&&
m
.
GetParameters
().
Length
==
0
));
}
var
expression
=
GetExpression
(
filterTerm
,
filterValue
,
propertyValue
,
bCaseSensitive
);
if
(
filterTerm
.
OperatorIsNegated
)
...
...
@@ -224,10 +233,23 @@ namespace Sieve.Services
{
innerExpression
=
Expression
.
Or
(
innerExpression
,
expression
);
}
dynamicQuery
=
GetDynamicQueryString
(
filterTerm
,
dynamicQuery
.
ToString
(),
filterValue
.
ToString
());
}
}
}
if
(
string
.
IsNullOrEmpty
(
dynamicQuery1
))
{
dynamicQuery1
=
"("
+
dynamicQuery
+
")"
;
}
else
{
dynamicQuery1
+=
" or "
+
"("
+
dynamicQuery
+
")"
;
}
if
(
outerExpression
==
null
)
{
outerExpression
=
innerExpression
;
...
...
@@ -245,7 +267,7 @@ namespace Sieve.Services
TSieveModel
model
,
IQueryable
<
TEntity
>
result
,
object
[]
dataForCustomMethods
=
null
,
bool
bCaseSensitive
=
false
)
bool
bCaseSensitive
=
false
)
{
if
(
model
?.
GetFiltersParsed
()
==
null
)
{
...
...
@@ -336,7 +358,31 @@ namespace Sieve.Services
?
result
:
result
.
Where
(
Expression
.
Lambda
<
Func
<
TEntity
,
bool
>>(
outerExpression
,
parameterExpression
));
}
private
static
string
GetDynamicQueryString
(
TFilterTerm
filterTerm
,
string
property
,
string
value
)
{
string
sResult
=
property
;
switch
(
filterTerm
.
OperatorParsed
)
{
case
FilterOperator
.
Equals
:
return
sResult
+
"="
+
value
;
case
FilterOperator
.
NotEquals
:
return
sResult
+
"!="
+
value
;
case
FilterOperator
.
GreaterThan
:
return
sResult
+
">"
+
value
;
case
FilterOperator
.
LessThan
:
return
sResult
+
"<"
+
value
;
case
FilterOperator
.
GreaterThanOrEqualTo
:
return
sResult
+
">="
+
value
;
case
FilterOperator
.
LessThanOrEqualTo
:
return
sResult
+
"<="
+
value
;
case
FilterOperator
.
Contains
:
return
sResult
+
".Contains("
+
value
+
")"
;
case
FilterOperator
.
StartsWith
:
return
sResult
+
".Contains("
+
value
+
")"
;
default
:
return
sResult
+
"="
+
value
;
}
}
private
static
Expression
GetExpression
(
TFilterTerm
filterTerm
,
dynamic
filterValue
,
dynamic
propertyValue
,
bool
bCaseSensitive
)
{
switch
(
filterTerm
.
OperatorParsed
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment