MVC + EF application with N-Layers

Asked

Viewed 149 times

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?

  • 1

    What is the need for this separation?

  • The error always occurs in the same Viewmodel ? Your Viewmodel Product does not have to instantiate any object in its create ?

  • 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.

  • 1

    Solved the problem?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.