Solved

Change FK key name Ef framework Code First

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Access PS SQLSERVER from powershell 1 29
Easiest intro into .NET CORE? 2 32
SQL Server 2012 and core licensing 5 30
Section based report in SSRS 14 31
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
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

734 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