“找不到类型或命名空间名称'ForeignKeyAttribute'(您是否缺少using指令或程序集引用?)”
“无法找到类型或命名空间名称'ForeignKey'(您是否缺少using指令或程序集引用?)”
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
using System.Data.Entity.ModelConfiguration.Conventions;
using System.Data.Entity;
namespace MvcApplication6.Models
{
public class tblRental
{
[Key()]
public int rental_id { get; set; }
public int room_id { get; set; }
public DateTime check_in { get; set; }
public DateTime check_out { get; set; }
public decimal room_cost { get; set; }
public long customer_ref { get; set; }
[ForeignKey("customer_ref")]
public virtual tblCustomerBooking Customer { get; set; }
}
public class tblCustomerBooking
{
[Key()]
public long customer_id { get; set; }
public string customer_name { get; set; }
public string customer_email { get; set; }
public virtual ICollection<tblRental> Rentals { get; set; }
}
有人知道ForeignKey引用是否已被更改?
感谢您的帮助,
标记
答案 0 :(得分:23)
我刚想通了我需要添加:
using System.ComponentModel.DataAnnotations.Schema;
之前我不需要移动它,所以我假设ForeignKey已被移动到架构命名空间下。
希望这有助于其他任何人,
谢谢,Mark