I have the following database:
An artist can have many titles. A title can be either a song or an album. In my code I have the following configuration:
public class AlbumConfiguration : EntityTypeConfiguration<AlbumDetail>
{
public AlbumConfiguration()
{
this.HasKey(a => a.Id);
this.Property(a => a.Title);
this.HasRequired(a => a.TitleDetail).WithOptional(t => t.Album);
this.ToTable("Albums");
}
}
public class ArtistConfiguration : EntityTypeConfiguration<ArtistDetail>
{
public ArtistConfiguration()
{
this.HasKey(a => a.Id);
this.Property(a => a.Name);
this.ToTable("Artists");
}
public class TitleConfiguration : EntityTypeConfiguration<TitleDetail>
{
public TitleConfiguration()
{
this.HasKey(a => a.Id);
this.Property(a => a.Title);
this.HasRequired(a => a.Artist).WithMany(j => j.Titles).HasForeignKey(a => a.ArtistId);
this.ToTable("Titles");
}
}
This is what I do when I want a query to display the albums for one artist:
IQueryable<AlbumDetail> artistDetail =
base.Query.Where(x => x.Id == artistId).Include("Titles").OfType<AlbumDetail>();
return artistDetail.ToList();
This is the query that was generated:
SELECT
[Extent1].[Id] AS [Id],
'0X0X' AS [C1],
[Extent2].[Title] AS [Title],
[Extent2].[ArtistId] AS [ArtistId],
[Extent3].[Id] AS [Id1],
[Extent1].[TitleDetail_Id] AS [TitleDetail_Id],
[Extent4].[Id] AS [Id2]
FROM [dbo].[Albums] AS [Extent1]
INNER JOIN [dbo].[Titles] AS [Extent2] ON [Extent1].[Id] = [Extent2].[Id]
LEFT OUTER JOIN [dbo].[Songs] AS [Extent3] ON [Extent1].[Id] = [Extent3].[TitleDetail_Id]
LEFT OUTER JOIN [dbo].[Albums] AS [Extent4] ON [Extent1].[Id] = [Extent4].[TitleDetail_Id]
When I now want a query to display the albums owned by an artist I get the following error :
Invalid column name 'TitleDetail_Id'. Invalid column name 'AlbumDetail_Id'. Invalid column name 'TitleDetail_Id'. Invalid column name 'TitleDetail_Id'. Invalid column name 'TitleDetail_Id'. Invalid column name 'TitleDetail_Id'. Invalid column name 'Song_Id'. Invalid column name 'AlbumDetail_Id1'. Invalid column name 'TitleDetail_Id'. Invalid column name 'Song_Id'. Invalid column name 'AlbumDetail_Id1'.
Can anyone help me?