What is causing the error 'ORA-00904: "o0"."ObservationId1": invalid identifier' in my EF Core query?

huangapple go评论54阅读模式
英文:

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(&quot;OBSERVATION&quot;, Schema = Constants.TABLE_SCHEMA_NAME)]
public class Observation : IEntity&lt;int&gt;
{
    [Key]
    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    [Column(&quot;OBSERVATIONID&quot;)]
    public override int Id { get; set; }

    public virtual ICollection&lt;ObservationCba&gt;? ObservationCbas { get; set; } = default;
}

[Table(&quot;OBSERVATIONCBA&quot;, Schema = Constants.TABLE_SCHEMA_NAME)]
public class ObservationCba : IEntity&lt;long&gt;
{
    [Key]
    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    [Column(&quot;OBSERVATIONCBAID&quot;)]
    public override long Id { get; set; }

    [Column(&quot;OBSERVATIONID&quot;)]
    public long ObservationId { get; set; }
}

And the error occurs on this query

var observations = await _dbContext.Observations
	.Include(c =&gt; 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.ObservationIdlong 类型。将 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.

huangapple
  • 本文由 发表于 2023年3月15日 21:06:04
  • 转载请务必保留本文链接:https://go.coder-hub.com/75745143.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定