C# 向数据库添加行时参数无效-
我当前在尝试向数据库添加行时遇到问题。。。这是visual studio 2013上的windows窗体应用程序。。。我有一个实体文件夹,其中上载了我的TargetCells表 我还试图从我正在创建的对象中取出所有内容,只做第一行。。所以我只传递了一个带有对象的项,但它仍然不喜欢这样。。。所以我不认为这是我的模型被打包/对象创建的方式 我的错误: 与“C# 向数据库添加行时参数无效-,c#,linq,entity-framework,C#,Linq,Entity Framework,我当前在尝试向数据库添加行时遇到问题。。。这是visual studio 2013上的windows窗体应用程序。。。我有一个实体文件夹,其中上载了我的TargetCells表 我还试图从我正在创建的对象中取出所有内容,只做第一行。。所以我只传递了一个带有对象的项,但它仍然不喜欢这样。。。所以我不认为这是我的模型被打包/对象创建的方式 我的错误: 与“System.Data.Entity.DbSet.Add(AssemblyTargets.Entities.TargetCells)”匹配的最佳重
System.Data.Entity.DbSet.Add(AssemblyTargets.Entities.TargetCells)
”匹配的最佳重载方法具有一些无效参数
在我的构造函数中:(db.TargetCells.Add(cellModel)行是我的错误发生的地方,我在它周围放了星星以帮助您找到它..)
我的模型看起来像:
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; }
}
}
你知道我做错了什么吗?异常会给你答案-你试图添加一个
CellModel
,而该方法需要一个AssemblyTargets.Entities.TargetCells
实例。我已经编辑了你的标题。请看“”,其中的共识是“不,他们不应该”。你能发布你的TargetCells设计吗?Charles Mager是正确的,我使用的是我的Cell1模型,而我本应该使用TargetCells
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; }
}
}