I sought some enlightenment on FreeNode IRC in the C# channel regarding how to have strong property references without invoking them, including without delegate implementation.
The problem I’ve been faced with is that nasty string-based property specifier in Gemli.Data’s DataModelQuery<TModel>:
var women = DataModel<Person>.NewQuery()
.WhereProperty["Gender"] == Gender.Female;
.SelectMany().Unwrap<Person>();
women.ForEach( woman => Hug(woman) );
I first asked the same IRC channel what initial thoughts were on the direction Gemli was going and that stupid string-based indexer was the first thing to come up. “It looks brittle.” Agreed. This is the part that bugs me the most about Gemli.Data at the moment—well, tied, along with the lack of individual field selection and aggregate function support.
But LINQ-to-SQL doesn’t have this problem, which is interesting because LINQ-to-SQL doesn’t have any proprietary, Microsoft-alone-can-see-it under-the-covers magic about it. Yet with LINQ you get strong property references, without invoking the properties as CLR property behavior.
var women = (from woman in People
where woman.Gender == Gender.Female
select woman).ToList();
women.ForEach( woman => Feed(woman) );
How? LINQ-to-SQL doesn’t even execute that binary comparison in the CLR, it converts it to T-SQL.
First I had recently assumed up until today that this was a lambda expression and your CLR object that reaches LINQ’s “where” expression must surely be a class inheritor that mocks its base with no literal implementation. I mentioned this to the IRC channel, though, and was immediately told it’s done with expression trees. I was given a sample of Expression<Func<T, U>>. What? I then came across this: http://www.interact-sw.co.uk/iangblog/2005/09/30/expressiontrees .. among a bunch of other articles and blog posts.
Looks like I still have a lot of homework this week because I’ve never looked at expression trees in C# before. Makes me feel like I’m behind, but there’s joy in knowing that I’m catching up in this and once I get caught up it’ll open up all kinds of new doors for Gemli.
(I might follow up on this blog entry inline, I just wanted to get something mentioned now since I’m heading to bed now and don’t want to lose the thought.)