English 中文(简体)
即便在安装了实体框架4.1之后,仍不承认相关属性
原标题:RelatedTo attribute not recognised, even after installation of Entity Framework 4.1

我忙着学习ASP.Net MVC, 所以我最近安装了MVC 4 在2010年视觉工作室专业。

http://www.luisrocha.net/2010/11/recating-complosite-keys-using-code.html" rel=“不跟随 no follown noreferrer" >http://www.luisrocha.net/2010/11/recating-complosite-keys-using-code.html

但视觉工作室找不到 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; }
    }
}
最佳回答

使用 Nuget 尝试安装新版本的 EF 。 它将解决 EF 的所有依赖性, 并确保您拥有最新版本 。 我不知道这里的属性是 相关 to 。 并且参见 < a href=> http://blogs. msdn. com/ b/ adonet/ archive/2011/ 03/15/ef-4-1- code- first- walktrave. aspx" rel= "nofollown noreferrer" 。 这里 < / a> 在数据说明部分中, 属性的关联性不在 EF4.1 发布中 。 但是您也可以这样做 。

      [ForeignKey("PlaylistId")] 
      public Playlist Playlist { get; set; }

      [ForeignKey("TrackId")] 
      public Track Track { get; set; }

EDIT RelatedTo attribute is replaced by ForeignKey and InverseProperty attributes in EF 4.1 RC

问题回答

暂无回答




相关问题
Entity Framework with MySQL connector in c#

I have been trying to get the Entity Framework to work in my web application using MySQL. It works fine on my local pc, but doesn t work when I put it on the server. Since the server is a shared ...

How Do I Create And Update A Many To Many Relationship With EF

I am using the Entity Framework with SQL Server. I have a many to many relationship between 2 tables. I have created a join table with just the primary key fields of the 2 tables. In the designer, the ...

Entity Framework with File-Based Database

I am in the process of developing a desktop application that needs a database. The application is currently targeted to SQL Express 2005 and works wonderfully. However, I m not crazy about having ...

Linq to enties, insert foreign keys

I am using the ADO entity framework for the first time and am not sure of the best way of inserting db recored that contain foreign keys. this is the code that i am using, I would appreciate any ...

Entity Framework - Many to many question

I have a table called ASB and a table called PeopleInvolved. There is a junction table called PeopleInvolved_ASB which simply contains an ASBID and a PeopleInvolvedID column. The columns act as a ...

Post back complex object from client side

I m using ASP.NET MVC and Entity Framework. I m going to pass a complex entity to the client side and allow the user to modify it, and post it back to the controller. But I don t know how to do that ...

ADO.NET Entity Data Model are not precise enough

I run this code: var cos = from k in _db.klienci_do_trasy where k.klient_id == 5 select k; but the query send to database is: SELECT * FROM `klienci_do_trasy` LIMIT 0, 30 why is it for, there ...