Captain Ramen

Here is my problem: I want to run linq queries behind a WCF service. I want this service to inspect the type being queried, and look for a parameter called UserAccount. If it finds it, I want it to add "&& UserAccountDBID = someGuid" to the query. So far this is what I have but I get runtime errors:


Code Snippet

if (hasUserAccountKey)

{

ParameterExpression p; BinaryExpression b; MemberExpression m;

p = Expression.Parameter(typeof(UserAccount), "UserAccount");

m = Expression.Property(p, typeof(UserAccount).GetProperty("DBID"));

b = Expression.Equal(m, Expression.Constant(new Guid("D6323BA8-7DC4-49F2-8637-475059FA467F")));

expression = Expression.And(expression, b);

}




Re: LINQ Project General How do I add a Clause to a Linq Query?

Keith Farmer

I think you need to post more information about this (more code, the actual error, etc).

One thing to keep in mind is that the name of the parameter isn't really significant: create new parameters only when they really are new, and reuse existing parameters if you want them to the refer to the same thing.

Also remember that you can compose new queries from existing ones: from x in baseQuery where x.DBID = someGuid...