Solved

Change FK key name Ef framework Code First

Posted on 2010-09-15
2
577 Views
Last Modified: 2013-11-07
Hi!
I'm using Ef Code first to map my database. I have a 1-m relation and the  default convention is POccurrence_id but ofc it cant find it, coz in my DB its named fkOccurrenceId.

How do i map the new FK name?

Best regards
Bjorn
0
Comment
Question by:YouKnowPochen
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 51

Expert Comment

by:Mark Wills
ID: 33690606
Well, the FK is not normally mapped to, rather it establishes indexes and a relationship between two tables so should use relatedto, and the mapping uses the FK key (because of the indexes).

"normal" naming conventions would suggest that the foreign key is likely to start with fk... and that is not the column in the database necessarily.

You will need to double check the tables specifically to clarify the naming conventions, or rather, the actual table and columns (and any constraints).
0
 

Accepted Solution

by:
YouKnowPochen earned 0 total points
ID: 33690910
Or i could use the DataAnnotation attribute RelatedTo, works just fine, but thank you for the answer.
And theconvention does not go with fk in the beginning i guess, since it was looking for fktablename_id
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

687 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