1

I have two entities on a context for which I've enabled Lazy loading. I'm using POCOs. When I load the first one, the related entities do not show up until I load the second one and navigate it's entities. More specifically, I have Currency (which is marked as virtual) as a related entity on CashAccount which inherits it from Account as well as on SuspenseAccount which also inherits it from Account. When I load SuspenseAccount, Currency is null. But if I load CashAccount and use it's Currency property, Currency for SuspenseAccount then gets loaded appropriately. Anyone with ideas on why this is and how to fix it?

4
  • Can you write down a brief sketch of this model with code and also the code how you load the entities? Commented Apr 21, 2012 at 12:17
  • Phew! I found out what the issue was! The SuspenseAccount class didn't have a public constructor (it's only constructor was marked internal). Apparently, this prevented the POCO LazyLoading logic from kicking and the relationships were fixed up after accessing another entity's relationships because the related entities were same for both. @Slauma - Thanks. It's sorted now. Commented Apr 21, 2012 at 12:26
  • That's interesting! Can you write this as answer, please, so people can see that the problem is solved. (You can accept then your own answer.) I had a similar phenomenon with private constructors some time ago (EF didn't create lazy loading proxies), but not with protected constructors. I hadn't guessed that internal constructors could be a problem. Commented Apr 21, 2012 at 12:32
  • A public or protected parameterless constructor is required for proxies so that the dynamically crated type that derives from your entity could be created. Here is the complete list of requirements for proxies: msdn.microsoft.com/en-us/library/dd468057.aspx Commented Apr 22, 2012 at 6:18

1 Answer 1

1

I found out what the issue was! The SuspenseAccount class didn't have a public constructor (it's only constructor was marked internal). Apparently, this prevented the POCO LazyLoading logic from kicking in and the relationships were fixed up after accessing another entity's relationships because the related entities were same for both.

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.