Kelvin
Kelvin

Reputation: 31

SubSonic 3 and multiple PK columns

I'm having problem with SubSonic 3 and multiple Primary Key columns. It seems like it isn't supported via the ActiveRecord T4 script.

In line 173 of Settings.ttinclude

return this.Columns.SingleOrDefault(x=>x.IsPK) ?? this.Columns[0];

It tries to get a Single Primary Key Column and failed.

Any solutions?

Upvotes: 1

Views: 1219

Answers (4)

elpipo
elpipo

Reputation: 124

I believe EntitySpaces does support them.

My 2cents-

-- this was intented to be an answer to womp just to say that NHibernate isn't the only well known ORM supporting composite keys. At least leave a comment (or an insult :p ) when downvoting --

Upvotes: 0

user1151
user1151

Reputation:

I'll tweak the templates to add support for this in the future (since a lot of people are having issues with it) but you can change this:

return this.Columns.SingleOrDefault(x=>x.IsPK) ?? this.Columns[0];

to this:

return this.Columns.Where(x=>x.IsPK).ToArray();

(this is free-handed) and then change the return type to Column[]. The change should be pretty simple from this point of view, but then you'd need to change the templates throughout.

I know people like composite keys - and they are particularly important for many/many, but (my opinion) I don't like the design. A table (that's not many/many) should have one PK to uniquely ID a row...

I also understand that many folks can't control such a thing :). Anyway - if you'd like to help and fork/push this, I'd really appreciate it.

Upvotes: 3

Jon Galloway
Jon Galloway

Reputation: 53145

You could potentially create a view which creates a primary key by concatenating the composite key columns. e.g. if they're varchar columns PK = COALESCE(K1, '|', K2, '|', K3). If they're numeric, you could do something similar by multiplying each key column by a multiplier to create a unique PK.

Upvotes: 0

womp
womp

Reputation: 116987

Many ORM products do not support composite keys due to the overwhelming complexity of doing so. As far as I know, NHibernate is the only well-known .Net ORM product that does.

Mindscape was discussing composite key support for version 3 of their Lightspeed product, but I don't know too much about it.

SubSonic does not currently support composite keys.

Upvotes: 3

Related Questions