2

I have a table called AccountValues that I would like to reference from my Account table. However rather than using AccountValuesId and AccountValues, I would like it to be a little more descriptive by prefixing MostRecent_ as follows:

[ForeignKey("AccountValues")]
public long MostRecent_AccountValuesId { get; set; }
public AccountValues MostRecent_AccountValues { get; set; }

My question is where should I place my ForeignKey attribute, so that I end up with an actual foreign key (e.g. FK_Something) and also have MostRecent_AccountValues automagically work?

Note: my convention is not to have plural table names. But here AccountValues is plural only because each row has a number of different values in it.

1 Answer 1

3

Problem is in your ForeignKey name on the public long MostRecent_AccountValuesId property. ForeignKey name should match the navigation property name as follows:

[ForeignKey("MostRecent_AccountValues")] // <-- Here it is
public long MostRecent_AccountValuesId { get; set; }
public AccountValues MostRecent_AccountValues { get; set; }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.