Solved

[ForeignKey] not working in System.ComponentModel.DataAnnotations

Posted on 2013-05-19
1
580 Views
Last Modified: 2013-05-23
I am using System.ComponentModel.DataAnnotations in MVC 4 and I am able to specify [Key] for the primary key but [ForeignKey] does not come up in the intellisense nor can I just type in [ForeignKey] without getting an error. Nothing that I have found yet directs me to a possible solution.

Can anyone help?
0
Comment
Question by:AmbassadorSpock
1 Comment
 
LVL 16

Accepted Solution

by:
Stephan earned 500 total points
ID: 39180692
The ForeignKeyAttribute is available in namespace "System.ComponentModel.DataAnnotations.Schema" inside library "System.ComponentModel.DataAnnotations.dll, v4.0.0.0"

This attribute is only available on .NET 4.5 (and not 4.0)
http://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.schema.foreignkeyattribute.aspx

If you are working in .NET 4.0 consider using the AssociationAttribute:
http://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.associationattribute(v=vs.100).aspx
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question