Solved

Change FK key name Ef framework Code First

Posted on 2010-09-15
2
573 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
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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

910 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

21 Experts available now in Live!

Get 1:1 Help Now