Solved

[ForeignKey] not working in System.ComponentModel.DataAnnotations

Posted on 2013-05-19
1
566 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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
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 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…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

743 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now