I have an issue and I just can't figure out what is causing the issue.
I have a redmine database with a 'journals' table http://puu.sh/1iRIt. Using the Visual Studio 2012 plugin EntityFramework Power Tools this has been reverse engineered into the following class:
public class Journal
{
public int id { get; set; }
public int journalized_id { get; set; }
public string journalized_type { get; set; }
public int user_id { get; set; }
public string notes { get; set; }
public System.DateTime created_on { get; set; }
}
and the map:
public class JournalMap : EntityTypeConfiguration<Journal>
{
public JournalMap()
{
// Primary Key
this.HasKey(t => t.id);
// Properties
this.Property(t => t.journalized_type)
.IsRequired()
.HasMaxLength(30);
this.Property(t => t.notes)
.HasMaxLength(65535);
// Table & Column Mappings
this.ToTable("journals", "redmine");
this.Property(t => t.id).HasColumnName("id");
this.Property(t => t.journalized_id).HasColumnName("journalized_id");
this.Property(t => t.journalized_type).HasColumnName("journalized_type");
this.Property(t => t.user_id).HasColumnName("user_id");
this.Property(t => t.notes).HasColumnName("notes");
this.Property(t => t.created_on).HasColumnName("created_on");
}
}
Now when I try to perform a select on the journals database using LINQ:
return context.Journals.Where(c => c.journalized_id == task.id);
I see that the following query is created:
- returnValue {SELECT
`Extent1`.`id`,
`Extent1`.`journalized_id`,
`Extent1`.`journalized_type`,
`Extent1`.`user_id`,
`Extent1`.`notes`,
`Extent1`.`created_on`,
`Extent1`.`Issue_id`
FROM `journals` AS `Extent1`
WHERE `Extent1`.`journalized_id` = @p__linq__0}
System.Linq.IQueryable<Synchronisation.Domain.Entities.Redmine.Journal> {System.Data.Entity.Infrastructure.DbQuery<Synchronisation.Domain.Entities.Redmine.Journal>}
What I don't understand is where the "Issue_id" is coming from, this query is causing a EntityCommandExecutionException (Inner exception: {"Unknown column 'Extent1.Issue_id' in 'field list'"} )
When I manually add the Issue_id column this problem is fixed (this fix must be reverted, no changes to the database structure are ment to be made)
I have no clue where this "Issue_id" coming from, does anybody have an idea how to find this out?
Cheers, Rick
Removed the custom reference between Journal and Issue (I had added a list of journals to my Issue class)
public List<Journal> Journals { get; set; }
After removing this list EntityFramework could figure out the query correctly again.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With