0
I am working on an MVC project with EF 6, and I am having a very curious problem, in some Viewmodel, the object that comes from my Dbcontext does not seem to persist and I get the generic message System.Nullreferenceexception.
The curious thing I say is because this occurs in a few layers, I’ve reviewed my mapping in Dbcontext, compared with those that are working and I can’t find a possible cause of the problem.
This project has several layers, well separated:
Software.Data
Software.Domain.
Software.Services
Software.Core.
Software.
My Dbcontext is initialized in Core, so when we need to call some method we do the following:
Products Recontroller Productore = new Productrecontroller();
viewModelProducts.Product = productCore.Returnproduct(id, Idshop);
Some views work normally, but in this particular case when I move to mine Partial the Model with the already loaded objects, it persists in the partial but on my first output call it accuses the error.
Has anyone ever had the problem or similar, which I could check the most or might have forgotten?
What is the need for this separation?
– Leonel Sanches da Silva
The error always occurs in the same Viewmodel ? Your Viewmodel Product does not have to instantiate any object in its create ?
– FernandoNomellini
Yes, in two Viewmodels. In her create I urge objects, even in debug mode I can read all the data, but when I call via Razor a certain property, ex. Product.Name, I get the Exception.
– Daniel Castro
Solved the problem?
– Renan