views:

1319

answers:

3

I have the following tables in the database (just a demo, of course):

Positions

PositionId

Limits

LimitId PositionId

I want to left join them into a single entity (always have position, not always have a limit attached to it):

Position

PositionId LimitId

I've seen articles regarding one-to-one mapping and "Table per type inheritence", and tried to implement the same method here, but with no sucess. Is that even possible?

A: 

I think what you want is an ordinary inner join where your foreign key (PositionID in the Limits table) is allowed to be null.

Robert Harvey
Not sure I get what you mean...The Limits table won't have a row in it, when no limits are presented for a specified position. But when it does, I want to present them in the same entity (and have multiple rows per one PositionId).
I can see that happening in a report, where you have grouping capabilities. Is this your intent? It's still an ordinary join, unless you don't want to see the row at all when there are no associated limits records. Then you do need a left-join, checking for Limits.PositionID Not Null.
Robert Harvey
The join issue is the least of my problems, is it possible to map those 2 tables into one entity?
+1  A: 

Nir,

Does this article contain what you are looking for?

Robert Harvey
A: 

Yes and no...In my scenario, the 2nd option is the applicable one, since I don't have the same primary key in both tables. so, I must create an updateable view...The problem with updateable view is that I can't modify fields which are in different tables and expect the database to handle it, unless I use "Instead of" triggers, which I really don't want to get into at all... So, I guess there's nothing out of the box for me...damn. (Unless you have another idea...)

Anyways, I really thank you for your help, it's much appreciated. Nir.

nirpi