System.Data.Entity.Core.EntityCommandExecutionException'

本文关键字:EntityCommandExecutionException Core Data Entity System | 更新日期: 2023-09-27 17:53:05

我尝试了3天添加一行到我的数据库与实体框架,但我不能:| ..现在我做了所有的基本工作添加行数据库…最后我得到了这个错误:

类型为"System.Data.Entity.Core"的未处理异常。EntityCommandExecutionException'发生在EntityFramework.SqlServer.dll中-附加信息:执行命令定义时发生错误。详情请参阅内部异常。

我执行了几次数据库,但是…!

代码:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.Entity.Validation;
using System.Diagnostics;
namespace WindowsFormsApplication6
{
    public partial class BuyForm : Form
    {
        public BuyForm()
        {
            InitializeComponent();
        }
        private void BuyForm_Load(object sender, EventArgs e)
        {

        }
        notebookEntities database = new notebookEntities();

        private void buyGridView_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
        }
        private void BuyForm_Load_1(object sender, EventArgs e)
        {
        }
        private void textBox6_TextChanged(object sender, EventArgs e)
        {
        }
        private void button1_Click(object sender, EventArgs e)
        {
            buytbl tbl = new buytbl
            {
                name = bnameTextBox.Text,
                price = int.Parse(bpriceTextbox.Text.ToString()),
                date = dateTimePicker1.Value,
                deadline = dateTimePicker2.Value,
                buyername = bbuyerTextBox.Text.ToString(),
                count = int.Parse(bcountTextBox.Text.ToString()),
                profit = int.Parse(bprofitTextBox.Text.ToString())

            };

            database.buytbls.Add(tbl);
            dataGridView1.DataSource = database.buytbls.ToList();
            database.SaveChanges();

        }
    }
}

和table:

//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated from a template.
//
//     Manual changes to this file may cause unexpected behavior in your application.
//     Manual changes to this file will be overwritten if the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace WindowsFormsApplication6
    {
        using System;
        using System.Collections.Generic;
        public partial class buytbl
        {
            public int id { get; set; }
            public string name { get; set; }
            public int price { get; set; }
            public int count { get; set; }
            public int  profit { get; set; }
            public System.DateTime date { get; set; }
            public System.DateTime deadline { get; set; }
            public string buyername { get; set; }
            public string description { get; set; }
        }
    }

请帮帮我!& lt; 3

System.Data.Entity.Core.EntityCommandExecutionException'

检查模型类和实际DB表之间的列名或外键映射名称是否不匹配。

更新您的模型。上下文应该与DB同步

相关文章:
  • 没有找到相关文章