Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8848407
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:24:59+00:00 2026-06-14T12:24:59+00:00

After countless hours I finally managed to get the fluent api settings to map

  • 0

After countless hours I finally managed to get the fluent api settings to map our complex existing SQL DB to POCO classes. There is one thing which I do not get to work and I am wondering if it might not be supported.

Class Power has:

List<Transaction> PowerTransactions;
Transaction LastPowerTransaction;
int PowerTransactionId;

Transactions is one to many where the Transaction Table has a FK pointing to Power.PowerID, that works fine.

Power has column PowerTransactionId and FK pointing to the TransactionId in the Transaction Table.

I set in fluent API:

Power has optional Last Transaction with required power

HasOptional(x => x.LastPowerTransaction).WithRequired(x => x.PowerLastPowerTransaction).Map(x =>     x.MapKey("PowerTransactionId"));

Powers TransactionId is 123 and PowerID is 1, when selecting Power.LastPowertransaction I get the transaction with id 1 not 123.

As the many to many does a select .. from PowerTransaction where PowerID=1, the One to One does the same thing instead of select .. from PowerTransaction where PowerID=123.

What am I missing here ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T12:25:00+00:00Added an answer on June 14, 2026 at 12:25 pm

    Mystere Man’s comment was not the real answer but using the mentioned tool led to the correct answer. EF4 code first only does one to one relationships with shared primary keys. The reveres engineering revealed this as NO one to one was created. Therefore my fluent mapping was wrong. This is a limitation in EF4 code first where one has to work around using one to one as “fake” one to many if the existing db does not use shared primary keys.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

After countless headaches and time wasted I managed to get the AudioRecorder working for
After countless hours trying to style a QComboBox, I'm stuck with the top and
Here's something I've been pondering after countless hours fixing JS to be cross-browser compatible
Despite having spent countless hours examining line of code, and after creating a fully
After reading countless guides, tutorials and intros, I still can't get my app onto
After solving countless problems with the hg-fast-export tool on Windows (from finicky python version
After some time researching and trying different things I still cannot get my @ExceptionHandler
After countless attempts and sieving through every SO answer + google result, it baffles
I've asked this question twice before, with no real progress. After trolling countless forum
New to C++ express, and after follow the winsock tutorial, getting countless of error.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.