I have a model:
public class ConstRouteFamily { [DatabaseGenerated(DatabaseGeneratedOption.Identity)] [Key] public long Id { get; set; } public long RouteId { get; set; } public long FamilyId { get; set; } public virtual ICollection<Family> Families { get; set; } } and the table:
CREATE TABLE [dbo].[ConstRouteFamilies] ( [Id] [BIGINT] IDENTITY(1,1) NOT NULL, [RouteId] [BIGINT] NOT NULL, [FamilyId] [BIGINT] NULL, CONSTRAINT [PK_ConstRouteFamilies] PRIMARY KEY CLUSTERED ([Id] ASC) ) ON [PRIMARY] GO ALTER TABLE [dbo].[ConstRouteFamilies] WITH CHECK ADD CONSTRAINT [FK_ConstRouteFamilies_ConstRoutes] FOREIGN KEY([RouteId]) REFERENCES [dbo].[ConstRoutes] ([Id]) GO ALTER TABLE [dbo].[ConstRouteFamilies] CHECK CONSTRAINT [FK_ConstRouteFamilies_ConstRoutes] GO ALTER TABLE [dbo].[ConstRouteFamilies] WITH CHECK ADD CONSTRAINT [FK_ConstRouteFamilies_Families] FOREIGN KEY([FamilyId]) REFERENCES [dbo].[Families] ([Id]) GO ALTER TABLE [dbo].[ConstRouteFamilies] CHECK CONSTRAINT [FK_ConstRouteFamilies_Families] GO Now, when I try to run the query:
var families = db.ConstRouteFamilies .Where(crf => crf.RouteId.Equals(route.Id)) .ToList(); I get an exception
Invalid column name 'ConstRoute_Id'
I looked at the SQL that was generated:
SELECT 1 AS [C1], [Extent1].[Id] AS [Id], [Extent1].[RouteId] AS [RouteId], [Extent1].[FamilyId] AS [FamilyId], [Extent1].[ConstRoute_Id] AS [ConstRoute_Id] FROM [dbo].[ConstRouteFamilies] AS [Extent1] Where did that ConstRoute_Id column came from? And how do I remove/fix that error?