我有一个(People)或Users对象,我正在使用类继承来创建各种对象。
但是我收到错误列INVALID COLUMN,当我添加对象(数据库中存在的Users_Accounts及其下面的相应列)时,出现错误
我在做什么错了?
错误消息 处理请求时发生未处理的异常。 SqlException:无效的列名称'Users_AccountsAccountID'。 无效的列名“ Users_AccountsAccountID”。 无效的列名“ Users_PhonePhoneID”。
namespace Accounts.i_EF.Accounts
{
public class Users
{
[Key]
public int UserID { get; set; }
public string Email { get; set; }
public Guid UniqueID { get; set; }
public DateTime Dates { get; set; }
public bool IsSuspended { get; set; }
public Users_Accounts Users_Accounts { get; set; }
}
public class Users_Accounts
{
[Key]
public int AccountID { get; set; }
public string UniqueID { get; set; }
public Title Title { get; set; }
public string First_Name { get; set; }
public string Last_Name { get; set; }
public Gender Gender { get; set; }
public Users_Phone Users_Phone { get; set; }
public string Email { get; set; }
public DateTime Dates { get; set; }
public bool IsSuspended { get; set; }
}
public enum Gender
{
male,female
}
和我的控制器代码
var user = HttpContext.User.Identity.Name.ToString();
var DataContext = _context.Users.Include(c => c.Users_Accounts);
return View(await DataContext.SingleOrDefaultAsync(c => c.Email == user && !c.IsSuspended));
答案 0 :(得分:1)
尝试以下代码:
namespace Accounts.i_EF.Accounts
{
public class Users
{
[Key]
public int UserID { get; set; }
public string Email { get; set; }
public Guid UniqueID { get; set; }
public DateTime Dates { get; set; }
public bool IsSuspended { get; set; }
public int UserAccountID { get; set; }
[ForeignKey(nameof(UserAccountID))]
public Users_Accounts Users_Accounts { get; set; }
}
public class Users_Accounts
{
[Key]
public int AccountID { get; set; }
public string UniqueID { get; set; }
public Title Title { get; set; }
public string First_Name { get; set; }
public string Last_Name { get; set; }
public Gender Gender { get; set; }
public int UserPhoneID { get; set; }
[ForeignKey(nameof(UserPhoneID))]
public Users_Phone Users_Phone { get; set; }
public string Email { get; set; }
public DateTime Dates { get; set; }
public bool IsSuspended { get; set; }
public int UserID { get; set; }
[ForeignKey(nameof(UserID ))]
public Users Users { get; set; }
}
public enum Gender
{
male,female
}