如何解决索引超出范围插入EF Core之后
我正在使用EF Core处理我的数据库,我想在我的Postgresql数据库中插入一条记录。
但是当我插入记录并进行保存更改时,应用会引发错误:
索引超出范围。必须为非负数且小于 集合。 (参数“索引”)
我知道在使用集合时会出现此错误,但是在这种情况下,我正在插入。
我的基本实体:
public abstract class BaseEntity: IBaseEntity<long>
{
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
[Key,Column("id",Order = 0)]
public long Id { get; set; }
[Column("createdAt")]
[DatabaseGenerated(DatabaseGeneratedOption.Computed)]
public DateTime CreatedAt{ get; set; }
}
来自业务层的插入
var entityToInsert = new Delivery()
{
State = 1,//active
Date = DateTime.Now,};
await this.UOW.Delivery.CreateAsync(entityToInsert);
await this.UOW.SaveChangesAsync();
我的通用存储库方法:
public async Task<TEntity> CreateAsync(TEntity entity)
{
await Context.AddAsync<TEntity>(entity);
return entity;
}
交付表定义:
id bigint // type identity "by default" autoincrment 1 per 1
state integer
date timestamp without time zone (not null)
createdAt timestamp without time zone (not null)
我在做什么错了?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。