Hi all

I'm new to the Entity Framework and trying to get my head around it but struggling somewhat.

I'm trying to do something basic like the below but it bombs out with a 'Null reference exception - Object reference not set to an instance of an object." when I try and do em.AddToCompanies(c); I'm just not able to debug it to get a decent error. I have manually checked there are no non-nullable fields that need filling in. tried catching an exception but I just get the same.

Can anyone tell me how I debug the Entity framework? I have tried on VS2008 and vs2010 with zero luck.

Company c = new Company();
            c.Code = "MyCode";
            c.FullName = "test co";
            c.IsActive = true;
            c.Language = "ENG";

7 Years
Discussion Span
Last Post by tig2810

You have indicated you are getting a "null reference" error, and you have provided a snippet that does not reveal the cause of the error; unless it is because "em" has not been instantiated. I suggest you zip up the project and attach it with data. If you cannot do that, at the very least you need to indicate which line causes the error so we can direct you to the possible cause.

EDIT: Just saw ddanbe replied with the same suspicion related to "em"...

Edited by DdoubleD: n/a


Sorry I forgot to mark as solved. My model got screwed up due to loads of refactoring and using vs2010 beta. I trashed the model and started again which fixed everything and my code worked.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.