Using the Entity Framework, I modeled a fairly simple database schema with an even more complex class hierarchy. In two places, I use unidirectional inheritance with a single column of the NVARCHAR (20) NOT NULL discriminator. In one of these two places it works great, no problem. But elsewhere, with an almost identical pattern, I get the following error:
Error 3023: problem with displaying fragments starting from lines 371, 375, 379, 382: Column MediaStream.MediaStreamTypeID has no default value and is not NULL. A column value is required to store entity data. An object with a key (PK) will not be rounded if: ((PK does not play the role of "MediaStream" in the AssociationSet "FK_MediaStream_SessionID" OR PK is not included in the "EntitySet" of MediaStream. EntityStyle is a type of [SlideLinc.Model] .MediaStream) AND ( The PC plays the role of "MediaStream" in the AssociationSet "FK_MediaStream_SessionID" OR PK is not included in the "EntitySet" of MediaStream. OR Entity is a type of [SlideLinc.Model]. MediaStream) And (PK plays the role of "MediaStream" in AssociationSet "FK_MediaStream_SessionID" or PK is in the "EntitySet" MediaStream))
Here's the definition of the table (not including various indexes, foreign keys, etc.):
CREATE TABLE [dbo].MediaStream( [MediaStreamID] UNIQUEIDENTIFIER NOT NULL, [SessionID] UNIQUEIDENTIFIER NOT NULL, [RtmpUri] nvarchar(250) NOT NULL, [MediaStreamTypeID] nvarchar(20) NOT NULL, CONSTRAINT PK_MediaStream PRIMARY KEY CLUSTERED ( [MediaStreamID] ASC )
I use the MediaStreamtypeID column as a discriminator: if it is set to “video”, the VideoMediaStream class must be created, and if it is set to “sound”, the AudioMediaStream class must be created.
The relevant parts of the EDMX file are as follows:
<EntitySetMapping Name="MediaStream"> <EntityTypeMapping TypeName="IsTypeOf(SlideLinc.Model.MediaStream)"> <MappingFragment StoreEntitySet="MediaStream"> <ScalarProperty Name="RtmpUri" ColumnName="RtmpUri" /> <ScalarProperty Name="MediaStreamID" ColumnName="MediaStreamID" /></MappingFragment></EntityTypeMapping> <EntityTypeMapping TypeName="IsTypeOf(SlideLinc.Model.VideoMediaStream)"> <MappingFragment StoreEntitySet="MediaStream" > <ScalarProperty Name="MediaStreamID" ColumnName="MediaStreamID" /> <Condition ColumnName="MediaStreamTypeID" Value="video" /></MappingFragment></EntityTypeMapping> <EntityTypeMapping TypeName="IsTypeOf(SlideLinc.Model.AudioMediaStream)"> <MappingFragment StoreEntitySet="MediaStream" > <ScalarProperty Name="MediaStreamID" ColumnName="MediaStreamID" /> <Condition ColumnName="MediaStreamTypeID" Value="audio" /></MappingFragment></EntityTypeMapping></EntitySetMapping> <AssociationSetMapping Name="FK_MediaStream_SessionID" TypeName="SlideLinc.Model.FK_MediaStream_SessionID" StoreEntitySet="MediaStream"> <EndProperty Name="MediaStream"> <ScalarProperty Name="MediaStreamID" ColumnName="MediaStreamID" /></EndProperty> <EndProperty Name="Session"> <ScalarProperty Name="SessionID" ColumnName="SessionID" /></EndProperty></AssociationSetMapping>
So, there are many things about this error that I am not getting:
(1) Why is this exact approach working for my other class hierarchy, but not for this? I thought this might be the Entity Design constructor confused, so I deleted this part of my hierarchy (in XML) and recreated it, but I still get it. I could try to recreate this whole damn thing, but damn it a lot of work, and if I have to do it very often, it doesn't leave me a good taste in essence.
(2) What is he complaining about first? I don’t understand how MediaStreamTypeID (which is not a member of the primary key) has anything to do with the primary key at all or why the fact that it cannot be null is a problem (especially when you consider that the same setting works elsewhere my model!).
Any thoughts or suggestions?