Asp.net
VS2012 RC 中無法辨識 ForeignKey
經過昨天的大量幫助,我在 asp.net4 beta 中遇到了一個已知錯誤 - 我升級到 VS2012 RC Express (4.5),現在 VS 在我的模型中報告了兩個錯誤,以前沒問題:
“找不到類型或命名空間名稱‘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 引用是否已更改?
謝謝你的幫助,
標記
我剛剛發現我需要添加:
using System.ComponentModel.DataAnnotations.Schema;我之前不需要移動它,所以我假設 ForeignKey 已移動到模式命名空間下。
希望這對其他人有幫助,
謝謝,馬克