0

I have recently updated a relation table in my database to have an additional field. When I updated my entity model from the database, this relationship has not been updated to contain this field. How can I get access to this property in my models?

Example:

People
---
PersonId - PKEY


PaymentPlans
---
PlanId - PKEY


PersonPaymentPlans
---
PersonId - FKEY
PlanId - FKEY
ConfidenceLevel - INT

In this case, when performing this entity query:

People
    .First(p => p.PersonId == pid)
    .Plans.First(p => p.PlanId == ppId)
    .ConfidenceLevel;

The ConfidenceLevel does not appear as an accessible property. How can I access this value or how can I get my EDMX to expose this property?

jokul
  • 1,269
  • 16
  • 37
  • did you create that column manually ? – Selman Genç Apr 12 '14 at 18:50
  • Yes [extra characters] – jokul Apr 12 '14 at 18:51
  • then there is no way to access it via entity framework, you need to generate and execute the sql query manualy,you can do that with entity framework (I mean you can execute the raw sql queries).Your question seems similar to my old question, see: http://stackoverflow.com/questions/20673785/how-can-i-add-extra-column-to-third-table-in-entity-framework if you want to do that with entity framework directly you have to create a dummy table (i.e. another type) to connect peoples and plans – Selman Genç Apr 12 '14 at 18:52

1 Answers1

1

I guess you are using database first and this has a little lack of feature to update this kind of change automatically you have to do it "half-manually".

First open your EDMX file and select the line that symbols the relation between those two tables and delete it, after this update your model from database and you should get almost your desired result.

I said almost because you mentioned in your query

.Plans.First(p => p.PlanId == ppId).ConfidenceLevel;

This wont be quite correct since EF will generate your PersonPaymentPlans table since consists of more than the two foreign key values. So your query will look more like this:

People
    .First(p => p.PersonId == pid)
    .PersonPaymentPlans.First(p => p.PlanId == ppId)
    .ConfidenceLevel;
Rand Random
  • 7,300
  • 10
  • 40
  • 88
  • Thanks, it did exactly what you said it would. It's a little annoying to not have it be tied to the relationship directly, but at the same time I can't see any way for that to work. – jokul Apr 12 '14 at 21:05