sideburns_01
sideburns_01
CC#
Created by sideburns_01 on 3/21/2024 in #help
Passing Lambda as a method parameter: Some issues
ok. Thanks again for the reference, that is very helpful. I will take a deep dive into that.
9 replies
CC#
Created by sideburns_01 on 3/21/2024 in #help
Passing Lambda as a method parameter: Some issues
dunno if reflection could be used to search for the nested Object class once I got the type T is?
9 replies
CC#
Created by sideburns_01 on 3/21/2024 in #help
Passing Lambda as a method parameter: Some issues
ok, thanks for the reference. I was trying to build something like this using expressions rather than sql syntax private sealed class referenceValue<T> { public int Value {get; set;} } public static IQueryable<T> WithIdExtension<T>(this IQueryable<T> query) where T : class { //entity we are applying filter to var memberEntity = Expression.Parameter(typeof(T)) //the property we want to access var accessEntityProperty = Expression.PropertyOrField(memberEntity, "SpecificId') var objectValue = new referenceValue<T> {Value = someInternalMethod.GetValue()} //this will parameterize value when converted to sql var value = Expression.PropertyOrField(Expression.Constant(objectValue, "Value"); var equalExpression = Expression.Equal(accessEntityParameter, value) Expression<Func<T, bool>> whereLambda = Expression.Lambda<Func<T, bool>>(equalExpression, memberEntity) return query.Where(whereLambda) }
9 replies
CC#
Created by sideburns_01 on 3/21/2024 in #help
Passing Lambda as a method parameter: Some issues
Hi. thanks for getting back to me. What I'm trying to do is create a dynamic extension query that can encapsulate the where statement in_context.ClassA.Where(a => a.ClassB.someVal == someReferenceVal). I was working with Expressions trees, and the problem there is getting the nested object and its propery to build that where clause. Not sure how to go about it. Though I am open to other ideas if my initial idea is wrong. The key idea being what options exist to encapsulate the .Where(a => a.ClassB.someVal == someReferenceVal)
9 replies