1
Answer

Linq Dynamic query for getting dynamic list based on Id

vinoth vinoth

vinoth vinoth

6y
220
1
I have created the Dynamic Model list.Here i need to get Dynamic list based on id.so I have tried the code. but i didn't get correct result.please help to get that
 
code:
 
public virtual List<TModel> GetAll(long index=0,string FieldName="")
{
try
{
_context.Set<TModel>().SelectByName<TModel,long>(FieldName).Distinct();
}
catch (Exception exc)
{
IsError = true;
ErrorMessage = exc.ToString();
Status = "Sorry,Not taken the Details";
}
return null;
}
public static IQueryable<V> SelectByName<T,V>(this IQueryable<T> source,
string FieldName)
{
ParameterExpression paramExp = Expression.Parameter(typeof(T), "x");
ConstantExpression valueexp = Expression.Constant(value);
MemberExpression memberExp = Expression.PropertyOrField(paramExp, FieldName);
var lambdaExp = Expression.Lambda<Func<T, V>>(memberExp, paramExp);
return source.Select(lambdaExp);
}
Answers (1)