C# 试图将新条目存储到数据库中的表中时出错存储更新、插入,影响了意外的行数(0)

C# 试图将新条目存储到数据库中的表中时出错存储更新、插入,影响了意外的行数(0),c#,sql,asp.net-mvc,entity-framework,C#,Sql,Asp.net Mvc,Entity Framework,我是ASP.NETMVC的新手。我编写了一个简单的程序来在表中保存一个新条目。对于同一个问题,我已经读了几个答案,但没有一个能帮到我。当我添加新对象,然后执行context.SaveChanges时,会出现以下错误: 受意外事件影响的存储更新、插入或删除语句 行数(0)。实体可能已被修改或删除,因为 实体已加载。刷新ObjectStateManager条目 我知道没有其他人在使用这个数据库。所以这不是问题所在。 代码如下所示 在数据库中我的表上,键为“EntryID”的表被设置为自动递增。我知道

我是ASP.NETMVC的新手。我编写了一个简单的程序来在表中保存一个新条目。对于同一个问题,我已经读了几个答案,但没有一个能帮到我。当我添加新对象,然后执行context.SaveChanges时,会出现以下错误:

受意外事件影响的存储更新、插入或删除语句 行数(0)。实体可能已被修改或删除,因为 实体已加载。刷新ObjectStateManager条目

我知道没有其他人在使用这个数据库。所以这不是问题所在。 代码如下所示

在数据库中我的表上,键为“EntryID”的表被设置为自动递增。我知道EntryID设置为0。但是,即使我在视图中将它手动更改为任何其他数字,它仍然会给我相同的错误

任何帮助都将不胜感激。谢谢

List.cshtml

@model MVC.Domain.Entities.InputList
@{
ViewBag.Title = "List";
}

@using(Html.BeginForm()) {
<p> Entry Number: @Html.TextBoxFor(x => x.EntryID)</p>
<p> Title       : @Html.TextBoxFor(x => x.TItle)</p>
<p> Description : @Html.TextBoxFor(x => x.Description) </p>
<input type="submit" value = "Save" />
}
EFProductRepository.cs

public class EFProductRepository : IProductRepository
{
   private EFDbContext context = new EFDbContext();

   public IQueryable<InputList> InputList
    {
        get { return context.InputList; }           
    }

   public void SaveProduct(InputList list)
   {           
       context.InputList.Add(list);           
       context.SaveChanges();
   }
}

public class EFDbContext : DbContext
{
    public DbSet<InputList> InputList { get; set; }    
}

[this]()的可能重复项如果您将主键设置为自动递增,则不应填充
EntryId
属性。您能显示InputList对象吗?@Carl我编辑了我的问题。“这就是你要的吗?”马克史密斯我也是这么想的。因此,我尝试不填充EntryId,但仍然得到相同的错误。谢谢你抽出时间,伙计们还有其他建议吗?
public class EFProductRepository : IProductRepository
{
   private EFDbContext context = new EFDbContext();

   public IQueryable<InputList> InputList
    {
        get { return context.InputList; }           
    }

   public void SaveProduct(InputList list)
   {           
       context.InputList.Add(list);           
       context.SaveChanges();
   }
}

public class EFDbContext : DbContext
{
    public DbSet<InputList> InputList { get; set; }    
}
public class InputList
{
    [Key]
    public int EntryID { get; set; }
    public string TItle { get; set; }
    public string Description { get; set; }        
}