Comments (11)
Use Sql.CharIndex()
function.
from linq2db.entityframeworkcore.
List is externally passed in, the internal does not know how much length, how to modify the middle ‘or’
from linq2db.entityframeworkcore.
ok, i know how to write ,Preset a few values
from linq2db.entityframeworkcore.
I'll post solution in 5 minutes
from linq2db.entityframeworkcore.
:) ,ok
from linq2db.entityframeworkcore.
There is:
public static class DynamicExtensions
{
private static IQueryable<T> WhereByItems<T, TV>(IQueryable<T> query, IEnumerable<TV> items,
Expression<Func<T, TV, bool>> predicate, Func<Expression, Expression, Expression> binaryFunc)
{
if (items == null) throw new ArgumentNullException(nameof(items));
if (predicate == null) throw new ArgumentNullException(nameof(predicate));
if (binaryFunc == null) throw new ArgumentNullException(nameof(binaryFunc));
Expression body = null;
foreach (var item in items)
{
var constant = Expression.Constant(item);
var current =
predicate.Body.Transform(e => e == predicate.Parameters[1] ? constant : e);
body = body == null ? current : binaryFunc(body, current);
}
return body == null ? query : query.Where(Expression.Lambda<Func<T, bool>>(body, predicate.Parameters[0]));
}
public static IQueryable<T> WhereOr<T, TV>(this IQueryable<T> query, IEnumerable<TV> items, Expression<Func<T, TV, bool>> predicate)
{
return WhereByItems(query, items, predicate, Expression.OrElse);
}
public static IQueryable<T> WhereAnd<T, TV>(this IQueryable<T> query, IEnumerable<TV> items, Expression<Func<T, TV, bool>> predicate)
{
return WhereByItems(query, items, predicate, Expression.AndAlso);
}
}
And usage:
using (var db = new HYWCRMContext(connectionString))
{
//this list is param,
var list = new string[] { "0-6", "7-9" };
// MemberResTagNames nvarchar is '0-6,10-12'
var temp = db.MemberInfo
.WhereOr(list, (m, i) => m.MemberResTagNames.IndexOf(i)>0)
.ToList();
}
from linq2db.entityframeworkcore.
Solution is based on our function Transform
. If you need pure mplementation, you have to use visitors.
from linq2db.entityframeworkcore.
add it to next version?
from linq2db.entityframeworkcore.
Nope, it is not suitable for this project. Almost every experinced programmer has these extensions.
We are thinking about additional library which may contain such helper functions.
from linq2db.entityframeworkcore.
ok, my programming skills are weak.
from linq2db.entityframeworkcore.
So just copy and enjoy ;)
from linq2db.entityframeworkcore.
Related Issues (20)
- IMergeable.UpdateWhenMatched: How can I provide custom setters for SOME of the fields, and use default for others HOT 7
- Library broken with Projectables HOT 3
- Merge doesn't include fields from the output expression HOT 2
- `TempTable<string>` doesn't work with `In` HOT 2
- System.ArgumentException: Expression of type 'System.Byte' cannot be used for constructor parameter of type 'System.Int32' after 7.5.0->7.6.0 upgrade HOT 4
- Setting `BulkCopyOptions` HOT 5
- Log sql query strings when executing InsertWhenNotMatched, UpdateWhenMatched
- System.Diagnostics.UnreachableException: The program executed an instruction that was thought to be unreachable
- "ORA-01704 string literal too long" exception generated when trying to "upsert" BLOB type column in Oracle
- Using EF Core release version 8.0 HOT 3
- Linq2Db fails to translate recursive CTE with ef core TPH HOT 2
- Warning Message for CreateLinqToDbConnection Method HOT 2
- Using CTE with EFCore db context query?
- MissingMethodException: Method not found: SetConvertExpression HOT 1
- Mapping EF `HasConversion<string>` ignored
- BulkCopy throws an Exception with ComplexProperty (Complex Type)
- Integration with EFCore.NetTopologySuite HOT 1
- Locking PostgreSQL Advice
- Not handling JSON-conversion of IList<string>, a native feature in EFCore HOT 2
- Issue with Merge into TPH table and EF Entities HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from linq2db.entityframeworkcore.