Home > Magiq > Magiq-to-sql: Associations issue

Magiq-to-sql: Associations issue

Following the Magiq saga, I started working on composite primary keys support for magiq-to-sql. With this feature we will be releasing the first version of Magiq, so we are very exited about it.

The first thing I have to say is there isn’t much information out there, so I use the “try&error” technique. My first approach was to declare the primary keys as several columns with “IsPrimaryKey=true” and, for the associations, using all the columns separated with commas in the ThisKey and OtherKey properties. Of course, I didn’t made up that, I saw it here. Good enough, it worked fine!

But (and there’s always a “but”)… doing the unit tests for this feature I realized we didn’t tested the insert and update of an association. I mean, this:

items.Set( x => x.AReference, x => x.AnotherReferenceOfTheSameType ).Update();

and

items.Insert( x => new Thing{ Reference = x.Reference } ).Into( things );

The problem here is that the generated query for this kind of expressions uses joins and subselects and, since I’m using a different query for each update set or value to insert, linq-to-sql will generate a different where for each (and a the parameters will use different table aliases).

The solution I see is to generate one single select for each property but, as I said here, it needs to use a dynamically generated class. I’m afraid I have no choice. I’ll post about it in the next days. If it works, we’ll be releasing Magiq 🙂

Oh, right, merry christmas.

Advertisements
  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: