Home > C#, Magiq > Magiq: The story of the API that wasn’t

Magiq: The story of the API that wasn’t

Today I’ll continue talking about Magiq. You can see my previous post here.

The first thing we thought with Seba was the API we wanted for Magiq. Since the first approach was about a mass update, we thought:

products.Where( x=> x.ExpirationDate >= DateTime.Now )
        .Update( x=> x.State = ProductState.Expired );

So, I make a extension method for IQueryable<T> called Update and receives a Expression<Action<T>>. Ok, it compiles, but when you try to use it, you get:

An expression tree may not contain an assignment operator

WTF?! ok, I know there is a (good?) reason for that (and there’s love inside of all of us, etc.) but… wtf?! Ok, “it should be better in 4.0”. Wrong! I tried and I get the same. Also, it seems like there are a lot of stuff you can’t do in an expression tree.

Finally, we got to the current API, that isn’t that cute but it works:

products.Where( x=> x.ExpirationDate <= DateTime.Now )
        .Set( x=> x.State, ProductState.Expired )
        .Update();

In the next post I’ll be talking about the implementation of magiq-to-sql.

Advertisements
Categories: C#, Magiq Tags: , ,
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: