英文:
What is causing the error 'ORA-00904: "o0"."ObservationId1": invalid identifier' in my EF Core query?
问题
当我包含一组外部数据时,我收到了ORA-00904: invalid identifier错误。
我的简化类如下:
[Table("OBSERVATION", Schema = Constants.TABLE_SCHEMA_NAME)]
public class Observation : IEntity<int>
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
[Column("OBSERVATIONID")]
public override int Id { get; set; }
public virtual ICollection<ObservationCba>? ObservationCbas { get; set; } = default;
}
[Table("OBSERVATIONCBA", Schema = Constants.TABLE_SCHEMA_NAME)]
public class ObservationCba : IEntity<long>
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
[Column("OBSERVATIONCBAID")]
public override long Id { get; set; }
[Column("OBSERVATIONID")]
public long ObservationId { get; set; }
}
错误发生在这个查询上:
var observations = await _dbContext.Observations
.Include(c => c.ObservationCbas)
.ToListAsync();
我的类设置有问题吗,还是我需要以不同的方式Include
?是什么导致了这个错误?
英文:
I'm getting an ORA-00904: invalid identifier error when I include a foreign collection of data.
My simplified classes are
[Table("OBSERVATION", Schema = Constants.TABLE_SCHEMA_NAME)]
public class Observation : IEntity<int>
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
[Column("OBSERVATIONID")]
public override int Id { get; set; }
public virtual ICollection<ObservationCba>? ObservationCbas { get; set; } = default;
}
[Table("OBSERVATIONCBA", Schema = Constants.TABLE_SCHEMA_NAME)]
public class ObservationCba : IEntity<long>
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
[Column("OBSERVATIONCBAID")]
public override long Id { get; set; }
[Column("OBSERVATIONID")]
public long ObservationId { get; set; }
}
And the error occurs on this query
var observations = await _dbContext.Observations
.Include(c => c.ObservationCbas)
.ToListAsync();
Do I have my classes setup wrong, or do I need to Include
differently? What is causing this error?
答案1
得分: 0
昨天我花了4个小时,今天花了1个小时搜索问题。我在这里发帖后20分钟找到了解决办法。
错误是由类型不一致引起的。Observation.Id
被定义为 int
类型;而 ObservationCba.ObservationId
是 long
类型。将 Observation.Id
改为 long
解决了我的问题。
英文:
Well, I spent 4 hours yesterday and 1 hour today searching for the problem. I figured it out 20 minutes after posting here.
The error is caused by inconsistent types. Observation.Id
is defined and an int
; ObservationCba.ObservationId
is a long
. Changing Observation.Id
to a long
fixed my problem.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论