提问人:siddhesh 提问时间:2/25/2023 最后编辑:marc_ssiddhesh 更新时间:2/25/2023 访问量:34
System.Data.SqlClient.SqlException:列名“Root_rootID”无效
System.Data.SqlClient.SqlException: Invalid column name 'Root_rootID'
问:
我是 ASP.NET 的新手,我正在学习 MVC 和 EF。使用“数据库中的代码优先”。ASP.NET 表中自动创建的。甚至 SQL 数据库中的表也没有列。rootId
marriage
Marriage
rootId
这是表类marriage
[Table("Marriage")]
public partial class Marriage
{
[Key]
public int marriageID { get; set; }
public int? spouseID { get; set; } = 0;
public int? childID { get; set; } = 0;
public virtual ICollection<Child> children { get; set; }
public virtual Spouse spouse { get; set; }
}
这是我的根表类:
[Table("Root")]
public partial class Root
{
[Key]
public int rootID { get; set; }
[Required]
[StringLength(100)]
public string name { get; set; }
[Column("class")]
[Required]
[StringLength(100)]
public string @class { get; set; }
[Required]
[StringLength(100)]
public string textClass { get; set; } = "emphasis";
public int? extraID { get; set; }
public int? marriagesID { get; set; }
public DateTime whenEntered { get; set; } = DateTime.UtcNow;
public DateTime whenModified { get; set; } = DateTime.UtcNow;
public virtual ICollection<Marriage> marriages { get; set; }
public virtual Extra extra { get; set; }
}
每当我像在模型中一样调用婚姻类或将数据保存在婚姻模型中时,只需将性别化即可
Sql = "SELECT \r\n [Extent1].[marriageID] AS [marriageID],
[Extent1].[spouseID] AS [spouseID],
[Extent1].[childID] AS [childID],
[Extent1].[Root_rootID] AS [Root_rootID]
FROM [dbo].[Marriage] AS [Extent1]"
因为不在类中,也不在数据库表中。为什么会发生此异常?我错过了什么?[Root_rootID]
Marriage
答: 暂无答案
评论