Ho una tabella nel mio database chiamato SEntries (vedi sotto l’istruzione CREATE TABLE). Ha una chiave primaria, un paio di chiavi esterne e niente di speciale. Ho molte tabelle nel mio database simili a quella, ma per qualche ragione, questa tabella ha finito con una colonna “Discriminator” sulla class Proxy EF.
Ecco come viene dichiarata la class in C #:
public class SEntry { public long SEntryId { get; set; } public long OriginatorId { get; set; } public DateTime DatePosted { get; set; } public string Message { get; set; } public byte DataEntrySource { get; set; } public string SourceLink { get; set; } public int SourceAppId { get; set; } public int? LocationId { get; set; } public long? ActivityId { get; set; } public short OriginatorObjectTypeId { get; set; } } public class EMData : DbContext { public DbSet SEntries { get; set; } ... }
Quando provo ad aggiungere una nuova riga a quella tabella, ottengo l’errore:
System.Data.SqlClient.SqlException: Invalid column name 'Discriminator'.
Questo problema si verifica solo se si eredita la class C # da un’altra class, ma SEntry non eredita da nulla (come si può vedere sopra).
In aggiunta a ciò, una volta ottenuto il tool-tip sul debugger quando passo il mouse sull’istanza EMData per la proprietà SEntries, visualizza:
base {System.Data.Entity.Infrastructure.DbQuery} = {SELECT [Extent1].[Discriminator] AS [Discriminator], [Extent1].[SEntryId] AS [SEntryId], [Extent1].[OriginatorId] AS [OriginatorId], [Extent1].[DatePosted] AS [DatePosted], [Extent1].[Message] AS [Message], [Extent1].[DataEntrySource] AS [DataE...
Qualche suggerimento o idea su dove andare in fondo a questo problema? Ho provato a rinominare il tavolo, la chiave primaria e alcune altre cose, ma niente funziona.
SQL-Table:
CREATE TABLE [dbo].[SEntries]( [SEntryId] [bigint] IDENTITY(1125899906842624,1) NOT NULL, [OriginatorId] [bigint] NOT NULL, [DatePosted] [datetime] NOT NULL, [Message] [nvarchar](500) NOT NULL, [DataEntrySource] [tinyint] NOT NULL, [SourceLink] [nvarchar](100) NULL, [SourceAppId] [int] NOT NULL, [LocationId] [int] NULL, [ActivityId] [bigint] NULL, [OriginatorObjectTypeId] [smallint] NOT NULL, CONSTRAINT [PK_SEntries] PRIMARY KEY CLUSTERED ( [SEntryId] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO ALTER TABLE [dbo].[SEntries] WITH CHECK ADD CONSTRAINT [FK_SEntries_ObjectTypes] FOREIGN KEY([OriginatorObjectTypeId]) REFERENCES [dbo].[ObjectTypes] ([ObjectTypeId]) GO ALTER TABLE [dbo].[SEntries] CHECK CONSTRAINT [FK_SEntries_ObjectTypes] GO ALTER TABLE [dbo].[SEntries] WITH CHECK ADD CONSTRAINT [FK_SEntries_SourceApps] FOREIGN KEY([SourceAppId]) REFERENCES [dbo].[SourceApps] ([SourceAppId]) GO ALTER TABLE [dbo].[SEntries] CHECK CONSTRAINT [FK_SEntries_SourceApps] GO