score:1
Accepted answer
i fooooooooooound. I'm very happy.
Only , I replaced the following method :
private static IEnumerable<Expression> GetConditionsWithSubModel(string search, ParameterExpression pe,
string parameter)
{
// output.Where(d => d.JN_NewsCategories.NewsCategoriesEn.Contains(""));
var expressions = new List<Expression>();
var strings = parameter.Split('$');
var modelName = strings[0];
var subModelName = strings[1].Split('.')[0];
var subModelField = strings[1].Split('.')[1];
foreach (var splitSeacrh in search.Split(' '))
{
Type modelClass = GetModel(modelName);
Type submodelClass = GetModel(subModelName);
ParameterExpression peSubModel = Expression.Parameter(modelClass, "d");
Expression leftSubModel = Expression.Property(peSubModel, modelClass.GetProperty(subModelName));
Expression ex = Expression.Property(leftSubModel, submodelClass.GetProperty(subModelField));
Expression rightSubModel = Expression.Constant(splitSeacrh);
MethodCallExpression conditionExpressionSubModel = Expression.Call(ex,
typeof(string).GetMethod("Contains"), rightSubModel);
expressions.Add(conditionExpressionSubModel);
}
return expressions;
}
with following method :
private static IEnumerable<Expression> GetConditionsWithSubModel(string search, ParameterExpression pe,
string parameter)
{
// output.Where(d => d.JN_NewsCategories.NewsCategoriesEn.Contains(""));
var expressions = new List<Expression>();
var strings = parameter.Split('$');
var modelName = strings[0];
var subModelName = strings[1].Split('.')[0];
var subModelField = strings[1].Split('.')[1];
foreach (var splitSeacrh in search.Split(' '))
{
Type modelClass = GetModel(modelName);
Type submodelClass = GetModel(subModelName);
Expression leftSubModel = Expression.Property(pe, modelClass.GetProperty(subModelName));
Expression ex = Expression.Property(leftSubModel, submodelClass.GetProperty(subModelField));
Expression rightSubModel = Expression.Constant(splitSeacrh);
MethodCallExpression conditionExpressionSubModel = Expression.Call(ex,
typeof(string).GetMethod("Contains"), rightSubModel);
expressions.Add(conditionExpressionSubModel);
}
return expressions;
}
Source: stackoverflow.com
Related Articles
- The parameter '***' was not bound in the specified LINQ to Entities query expression
- The parameter 'd' was not bound in the specified LINQ to Entities query expression
- "The parameter was not bound in the specified LINQ to Entities query expression." Specification Pattern And
- The parameter 'p' was not bound in the specified LINQ to Entities query expression
- Getting error "The parameter was not bound in the specified LINQ to Entities query expression."
- LINQ query to get all entities with member of specified type
- code first approach error: the specified type member 'yyyxx' is not supported in linq to entities
- LINQ Entities build Query at Runtime 'The parameter is not in scope.' LinqKit
- How to LINQ Query Code First generated EF6 hierarchical entities (entities within entities)?
- Generic Linq query to get array of entities with specified keys
- Entity Framework Code First - The entity or complex type cannot be constructed in a LINQ to Entities query
- Pass linq to entities query as parameter and execute against different objects
- Entity framework linq query Include() multiple children entities
- How do you construct a LINQ to Entities query to load child objects directly, instead of calling a Reference property or Load()
- Casting to a derived type in a LINQ to Entities query with Table Per Hierarchy inheritance
- LINQ query to perform a projection, skipping or wrapping exceptions where source throws on IEnumerable.GetNext()
- Linq query built in foreach loop always takes parameter value from last iteration
- Linq error generic parameter or the query must use a nullable type
- How do you return a default value if a LINQ to entities query returns no values
- Enumerable.Empty<T>().AsQueryable(); This method supports the LINQ to Entities infrastructure and is not intended to be used directly from your code
- LINQ to Entities / LINQ to SQL: switching from server (queryable) to client (enumerable) in the middle of a query comprehension?
- Dynamically build select list from linq to entities query
- The entity or complex type ... cannot be constructed in a LINQ to Entities query
- Efficient LINQ to Entities query
- A type that implements IEnumerable 'System.Collections.Generic.List`1' cannot be initialized in a LINQ to Entities query
- Specified cast is not valid Linq Query
- Retrieve single Entity Framework entities using a LINQ query or GetObjectKey?
- Problem with LINQ to Entities query using Sum on child object property
- Is there any way to create a LINQ query as a variable without having the data source (yet)?
- Linq to entities extension method inner query (EF6)
- Sort out duplicates in one row but keep a specific one
- C# LINQ xml parsing using "PreviousNode"
- Check if nullable boolean has value and if all are equal from list
- LINQ Query in DataTable
- Assignment of property if not null, possible with null-coalecing?
- Using System.Linq assembly in SQL CLR UDF
- Using Linq to select from a List in a List with Contains
- Angular js can't fetching data from ASP.Net Identity default user table
- Fill ComboBox with Results of LINQ Query, Directly
- Retrieve ID from database in mvc
- Fluent mongo Count() performance
- c# linq to xml error: cannot implicitly convert type
- C# List and HtmlParse
- ArrayIndex is not supported in LINQ to Entities
- Linq-to-SQL fails to reflect changes in one stored procedure
- How to select from 3 tables in a series using Linq?
- Declaring DataRow within a foreach or for Loop
- MVC linq to sql sum
- C# return generic list of objects using linq
- Difference between System.Collections.Generic.List<T>.ToArray() and System.Linq.Enumerable.ToArray<T>()?