Entityreference entitykey null


















Download Microsoft Edge More info. Contents Exit focus mode. Entity Reference. DataClasses Assembly: EntityFramework. It used the source entity's entitykey to query the source record and get the foriegnkey from the database then grab the data. Very clever indeed. Even when the EntityREference. EntityKey is populated, the query is written this same way.

So in the long run, that EntityKEy is only used for building relationships within ObjectContext and has nothing to do with query construction, right? There's only one difference though. I talked to Colin about this and given my explanation he is confused You are correct that the precense of the EntityKey on the EntityReference does not affect the the Load query. This would be a great optimization for our next release though. Unfrotunately the behavior you are seeing is not expected at all and my internal testing doesn't repro this issue.

When you call Load on an EntityReference, you should always get the entity value set. The case where the entity value is set to null only occurs when this is a I am assuming that is not the case since you say an EntityKey there, though. Is it possible that the foreign key is set to a value, but that value does not correspond to an actual row in another table not sure how you'd get into such a state?

Also, do you have any constraints on this relationship? I doubt that would make a difference, but I'm jst trying to see all the pieces to the puzzle. What I'm testing is how to remove a foreign key and while I was futzing with that by setting the entityreference.

Entity Reference. Entity Key Property Reference Is this page helpful? Please rate your experience Yes No. Any additional feedback? Namespace: System. These two lines, even if successful, it seems to me, would do nothing:. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. EntityReference has an EntityKey property value that does not match?

Ask Question. Asked 12 years, 4 months ago. Active 12 years, 4 months ago. Viewed 7k times. When I try and add the entity in question to the set see code below I get the following error: "The object could not be added or attached because its EntityReference has an EntityKey property value that does not match the EntityKey for this object.

Fax; contactToCreate. Extension; contactToCreate. FirstName; contactToCreate. MiddleName; contactToCreate. LastName; contactToCreate. PhoneNumber; contactToCreate. StreetAddress; contactToCreate. PostalCode; contactToCreate. ContactEmail; contactToCreate.



0コメント

  • 1000 / 1000