我忙着学习ASP.Net MVC, 所以我最近安装了MVC 4 在2010年视觉工作室专业。
但视觉工作室找不到 relateto 属性。 我读到 < a href=> https://stackoverflow.com/ questions/5499969/entity-framework-ctp-5-contriptte-not-work> 这个问题 , 这可能是由于实体框架4.1没有安装所致。 我检查了 < em> System.Data. entity. dll 的版本号, 并给出了版本4. 0.00, 运行时间版本v4. 0. 30319。 所以在我看来, 这似乎是安装在我的计算机上的 EF 4. 0版本。 我可能错了...
我从“http://www.microsoft.com/en-us/download/details.aspx?id=26825” rel=“不跟随无悔者”>here 并安装了EF 4.1,但“em'system.Data.Entity.dll 的版本数字似乎没有改变,而“em'em's relate to 属性仍然无效。有人知道安装出了什么问题,我怎样才能修好它吗?
<强 > UPATE: 强 >
我按照 < a href=> 上的指示安装了“实体框架”。 http://nuget.org/packages/EntityFramework” rel=“nofollown noreferrer” > this site , 控制台说它安装了“em>EntyFramework 5. 0.0-rc ,但“em>system.Data.intity.dll 的版本似乎没有变化。
否, 我未包括 using systems.Data.Entity , 因为英特尔利森斯没有告诉我要包括。 我确实包括了 System.componentModel.DataNotations 和 使用系统。 commonentModel.DataNotations. Schema , 因为这些是 Key 和 Column 属性的要求。 Intellisens请我使用“ em > 的Generate 类, 与 相关, 并添加了 using Systems.Data. < 实体/em > 并不改变这一点。
我的代码是用来给那些要求它的人的,尽管这正是我在问题中联系到的辅导课的代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity;
namespace Example
{
public class PlaylistTrack
{
[Key, Column(Order = 1)]
public int PlaylistId { get; set; }
[Key, Column(Order = 2)]
public int TrackId { get; set; }
[RelatedTo(ForeignKey = "PlaylistId")]
public Playlist Playlist { get; set; }
[RelatedTo(ForeignKey = "TrackId")]
public Track Track { get; set; }
}
}