If I have two tables, ProductVersion and FrameVersion, and I have a one to one relationship between the two tables. The table FrameVersion then relates to FrameColor and FrameSize which each should return collections for the colors and sizes.
Why is the property product.ProductVersion returning a collection? Since there is a one to one relation I expected that the ProductVersion property should return and single entity. Is it possible to get the one to one relationship property to return only a single entity?
The code that I'm using the get the FrameVersion currently looks like this.
FrameVersionEntity frameVersion = (FrameVersionEntity)productVersion.FrameVersion[0];
I would like to be able to do this instead.
FrameVersionEntity frameVersion = (FrameVersionEntity)productVersion.FrameVersion;
Here is the DDL:
CREATE TABLE [ProductVersion] (
[ProductVersionID] int identity(1,1) NOT NULL,
[ProductID] int NOT NULL,
[ActiveState] char(1) DEFAULT ('3') NOT NULL,
[DistributorID] int NOT NULL,
[DistributorNumber] varchar(30) DEFAULT ('') NOT NULL
)
GO
CREATE TABLE [FrameVersion] (
[ProductVersionID] int NOT NULL,
[FrameSizeID] int NOT NULL,
[FrameColorID] int NOT NULL
)
GO
CREATE TABLE [FrameSize] (
[FrameSizeID] int identity(1,1) NOT NULL,
[FrameID] int NOT NULL,
[FrameSize] decimal(4,2) DEFAULT (0) NOT NULL
)
GO
CREATE TABLE [FrameColor] (
[FrameColorID] int identity(1,1) NOT NULL,
[FrameID] int NOT NULL,
[Color] varchar(50) DEFAULT ('') NOT NULL
)
GO
ALTER TABLE [ProductVersion] ADD CONSTRAINT [PK_ProductVersion]
PRIMARY KEY NONCLUSTERED ([ProductVersionID])
GO
ALTER TABLE [FrameColor] ADD CONSTRAINT [PK_FrameColor]
PRIMARY KEY NONCLUSTERED ([FrameColorID])
GO
ALTER TABLE [FrameSize] ADD CONSTRAINT [PK_FrameSize]
PRIMARY KEY NONCLUSTERED ([FrameSizeID])
GO
ALTER TABLE [FrameVersion] ADD CONSTRAINT [PK_FrameVersion]
PRIMARY KEY ([ProductVersionID], [FrameSizeID], [FrameColorID])
GO
ALTER TABLE [FrameVersion] ADD CONSTRAINT [FK_FrameVersion_FrameColor]
FOREIGN KEY ([FrameColorID]) REFERENCES [FrameColor] ([FrameColorID])
GO
ALTER TABLE [FrameVersion] ADD CONSTRAINT [FK_FrameVersion_FrameSize]
FOREIGN KEY ([FrameSizeID]) REFERENCES [FrameSize] ([FrameSizeID])
GO
ALTER TABLE [FrameVersion] ADD CONSTRAINT [FK_FrameVersion_ProductVersion]
FOREIGN KEY ([ProductVersionID]) REFERENCES [ProductVersion] ([ProductVersionID])
GO
Is the problem that I have a composite primary key on the three columns in FrameVersion?
Regards,
Aaron