【发布时间】:2012-10-29 15:51:41
【问题描述】:
我有一个问题,我就是不知道是什么导致了这个问题。
我有一个 redmine 数据库,其中有一个“期刊”表 http://puu.sh/1iRIt。 使用 Visual Studio 2012 插件 EntityFramework Power Tools 已将其反向工程为以下类:
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");
}
}
现在,当我尝试使用 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>}
我不明白“Issue_id”是从哪里来的,这个查询导致了 EntityCommandExecutionException(内部异常:{“Unknown column 'Extent1.Issue_id' in 'field list'”})
当我手动添加 Issue_id 列时,此问题已修复(此修复必须恢复,无需更改数据库结构)
我不知道这个“Issue_id”是从哪里来的,有人知道如何找出来吗?
干杯, 瑞克
【问题讨论】:
-
尝试用 XML 编辑您的 Edmx 模型,然后搜索
Issue_Id,您的模型中有什么吗? -
是的,但不在期刊 EntitySet、EntityType 或 EntityTypeMapping 中。而且journal表和其他表之间没有定义关系
-
您是否在 Journal 和 Issue 之间添加了非电动工具创建的引用?
-
啊,是的,我做到了:) 我会删除那个引用
标签: entity-framework visual-studio-2012 redmine