【发布时间】:2018-03-31 11:29:00
【问题描述】:
我正在尝试在实体框架中使用此函数插入数据,但没有 MVC
protected void SaveBranch_Click(object sender, EventArgs e)
{
if (DropDownBranchSchool.Text == string.Empty)
{
}
else
{
branch newBranch = new branch(txtBoxBranchName.Text, txtBoxBranchLocation.Text, txtBoxBranchPhone.Text, txtBoxBranchEmail.Text, Int32.Parse(DropDownBranchSchool.Text));
_SchoolDBEntity.branches.Add(newBranch);
_SchoolDBEntity.SaveChanges();
Response.Redirect("Default.aspx");
}
}
有关此异常的其他信息是:
“概念端类型'DatabaseDBModel.student'中成员'SchoolId'的类型'Edm.String'与对象端类型'中成员'SchoolId'的类型'System.Int32'不匹配' SchoolManagementSystemOOP.Models.student'。”
我的分支类代码如下:
public partial class branch
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
public branch(string name, string location, string phone, string email, int schoolId)
{
this.students = new HashSet<student>();
BName = name;
BLocation = location;
BPhone = phone;
BEmailID = email;
SchoolId = schoolId;
}
public int BId { get; set; }
public string BName { get; set; }
public string BLocation { get; set; }
public string BPhone { get; set; }
public string BEmailID { get; set; }
public int SchoolId { get; set; }
public virtual school school { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<student> students { get; set; }
}
}
学生班级代码:
public partial class student
{
public int Id { get; set; }
public string FName { get; set; }
public string LName { get; set; }
public string Phone { get; set; }
public string EmailId { get; set; }
public string SchoolId { get; set; }
public string BranchId { get; set; }
public virtual branch branch { get; set; }
public student(string fname, string lname, string phone, string email, string schoolId, string branchId )
{
FName = fname;
LName = lname;
Phone = phone;
EmailId = email;
SchoolId = schoolId;
BranchId = branchId;
}
}
我想要一些关于是什么导致异常的见解和线索,我还尝试将学校的 int 类型更改为 string 的类型。
【问题讨论】:
-
请添加学生班级
标签: c# asp.net entity-framework-6 db-first