问题描述
我正在使用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 (将#修改为@)