我目前在尝试向数据库添加行时出现问题...这是Visual Studio 2013上的一个Windows窗体应用程序...我有一个实体文件夹,我的TargetCells表已上传...
我也尝试从我正在创建的对象中取出所有内容,然后执行第一行..这样我只使用该对象传递了1个项目,但它仍然不喜欢...所以我不要认为我的模型被打包/对象创建的方式....
我的错误:
“
System.Data.Entity.DbSet<AssemblyTargets.Entities.TargetCells>.Add(AssemblyTargets.Entities.TargetCells)
”的最佳重载方法匹配包含一些无效参数
在我的构造函数中:(行db.TargetCells.Add(cellModel)是我的错误发生的地方,我把星星围绕它来帮助你找到它..)
Cell1Model cellModel = new Cell1Model
{
cell = 1,
DateTime = Convert.ToDateTime(today),
customerdemand = Convert.ToInt32(txtCusDemand.Text),
StartTime = Convert.ToDateTime(txtTeamStart.Text),
Break1 = Convert.ToDateTime(txtBreak1Time.Text),
Break2 = Convert.ToDateTime(txtBreak2Time.Text),
Break3 = Convert.ToDateTime(txtBreak3Time.Text),
TimeforBreak1 = Convert.ToInt32(txtBreak1.Text),
TimeforBreak2 = Convert.ToInt32(txtBreak2.Text),
Timeforbreak3 = Convert.ToInt32(txtBreak3.Text),
Lunch = Convert.ToDateTime(txtLunch1Time.Text),
TimeforLunch = Convert.ToInt32(txtLunchBreak.Text)
};
// Add the new object to the TargetCells collection.
***db.TargetCells.Add(cellModel);***
try
{
db.SaveChanges(cellModel);
}
catch (Exception)
{
Console.WriteLine(e);
// Make some adjustments.
// ...
// Try again.
db.SaveChanges();
}
我的模特看起来像:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using AssemblyTargets.Models;
using AssemblyTargets.Entities;
namespace AssemblyTargets.Models
{
class Cell1Model
{
public int recid { get; set; }
public int? cell { get; set; }
public DateTime? DateTime { get; set; }
public int? customerdemand { get; set; }
public DateTime? StartTime { get; set; }
public DateTime? Break1 { get; set; }
public int? TimeforBreak1 { get; set; }
public DateTime? Break2 { get; set; }
public int? TimeforBreak2 { get; set; }
public DateTime? Break3 { get; set; }
public int? Timeforbreak3 { get; set; }
public DateTime? Lunch { get; set; }
public int? TimeforLunch { get; set; }
}
}
任何想法我做错了什么?