Entity framework EntityFramework是否尝试选择一个不存在的列?
我有一个问题,我就是不知道是什么导致了这个问题 我有一个redmine数据库和一个“journals”表。 使用Visual Studio 2012插件EntityFramework Power Tools,已将其反向工程到以下类别中:Entity framework EntityFramework是否尝试选择一个不存在的列?,entity-framework,visual-studio-2012,redmine,Entity Framework,Visual Studio 2012,Redmine,我有一个问题,我就是不知道是什么导致了这个问题 我有一个redmine数据库和一个“journals”表。 使用Visual Studio 2012插件EntityFramework Power Tools,已将其反向工程到以下类别中: public class Journal { public int id { get; set; } public int journalized_id { get; set; } public strin
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; }
}
和地图:
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");
}
}
公共类日志映射:EntityTypeConfiguration
{
公共新闻地图(
{
//主键
this.HasKey(t=>t.id);
//性质
this.Property(t=>t.journalized\u类型)
.IsRequired()
.HasMaxLength(30);
this.Property(t=>t.notes)
.HasMaxLength(65535);
//表和列映射
本表为ToTable(“日记账”、“红矿”);
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\u id).HasColumnName(“user\u id”);
this.Property(t=>t.notes).HasColumnName(“notes”);
this.Property(t=>t.created_on).HasColumnName(“created_on”);
}
}
现在,当我尝试使用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>}
返回context.Journals.Where(c=>c.journalized\u id==task.id);
我看到创建了以下查询:
-返回值{SELECT
`Extent1`.`id`,
`Extent1`.`journalized_id`,
`Extent1`.`journalized_type`,
`Extent1`.`user\u id`,
`Extent1`.`notes`,
`Extent1`.`在`上创建`,
`Extent1`.`问题号`
从'journals'改为'extend1`
其中`Extent1`.`journalized\u id`=@p\u linq\u 0}
System.Linq.IQueryable{System.Data.Entity.Infrastructure.DbQuery}
我不明白的是“问题id”来自何处,此查询导致EntityCommandExecutionException(内部异常:{“字段列表”中的“未知列”Extent1.Issue_id})
当我手动添加Issue_id列时,此问题已修复(必须恢复此修复,不需要对数据库结构进行任何更改)
我不知道这个“问题”是从哪里来的,有人知道如何找到它吗
干杯,
里克删除了期刊和期刊之间的自定义引用(我已将期刊列表添加到我的期刊类中)
公共列表日记帐{get;set;}
删除此列表后,EntityFramework可以再次正确计算查询。尝试用XML编辑Edmx模型,并搜索
问题Id
,它在模型中是否有任何内容?是的,但在EntitySet、EntityType或EntityTypeMapping中没有。日志表和其他表之间没有定义任何关系您是否在日志和问题之间添加了不是由power tool创建的引用?啊,是的,我添加了:)我将删除该引用
public List<Journal> Journals { get; set; }