これは、データをテーブルに保存しようとしたときに発生するエラーです。私はMVCで足場を作成しました。作成ボタンをクリックすると、フォームにデータを入力した後、以下のエラーが発生します。
エラー:
An exception of type 'System.Data.Entity.Infrastructure.DbUpdateException' occurred in EntityFramework.dll but was not handled in user code
Additional information: Unable to update the
EntitySet
'CustormerD
' because it has aDefiningQuery
and no<InsertFunction>
element exists in the<ModificationFunctionMapping>
element to support the current operation.
コントローラコード:
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create([Bind(Include="custid,name,cell_No,address,date,time,serviceNo")] CustormerD custormerd)
{
if (ModelState.IsValid)
{
db.CustormerDs.Add(custormerd);
db.SaveChanges();
return RedirectToAction("Index");
}
return View(custormerd);
}
下表コード:
public partial class CustormerD
{
public int custid { get; set; }
public string name { get; set; }
public Nullable<int> cell_No { get; set; }
public string address { get; set; }
public Nullable<System.DateTime> date { get; set; }
public Nullable<System.TimeSpan> time { get; set; }
public Nullable<int> serviceNo { get; set; }
}
SQLコード
CREATE TABLE [dbo].[CustormerD](
[custid] [int] IDENTITY(1,1) NOT NULL,
[name] [nchar](20) NULL,
[cell_No] [int] NULL,
[address] [nchar](20) NULL,
[date] [date] NULL,
[time] [time](7) NULL,
[serviceNo] [int] NULL
) ON [PRIMARY]
テーブルにプライマリキーがない場合、このエラーが発生する可能性があります。 –
'custid'に' '[Key]'を追加してください –
私のデータベーステーブルで何が失敗したのか教えてください。 – sibonile