I have the following sentence:
var customers = from customer in Context.ps_customer
select customer;
As you can see, it is the most simple sentence in the world. Well, it throws a NullReferenceException, and I don't have any idea why. in fact, the exception is thrown at
List<ps_customer> clientes = customers.ToList<ps_customer>();
but if I set a breakpoint in the Linq sentence and try to see the customers value, I have the NullReferenceException.
Does anyone have any idea why I get this exception?
EDIT: I am going to provide a bit more information:
MyEntityModel Context = new MyEntityModel();
var solicitudes = from solicitud in Context.ps_orders
where solicitud.date_add.Year == fecha.Year &&
solicitud.date_add.Month == fecha.Month &&
solicitud.date_add.Day == fecha.Day
select solicitud;
//This return correct data
ps_orders orden = solicitudes.ToList<ps_orders>().FirstOrDefault();
var customers = from customer in Context.ps_customer
where customer.id_customer == orden.id_customer
select customer;
var orden_detalles = from oDetalle in Context.ps_order_detail
where oDetalle.id_order == orden.id_order
select oDetalle;
var direcciones = from oDireccion in Context.ps_address
where oDireccion.id_address == orden.id_address_delivery
select oDireccion;
ps_address direccion = direcciones.FirstOrDefault(); //Correct data
List<ps_order_detail> detalles = orden_detalles.ToList<ps_order_detail>(); //Correct data
ps_customer clientes = customers.FirstOrDefault(); //NullReferenceException
I am totally sure that ps_customer has data, 2 rows to be specific, and I have deleted the ps_customer entity from the .edmx and I have added it again, an it still happens
Thank you very much!
EDIT 2: I have copied the create statement of the table, created a new table called customerTwo, inserted new data, and it still fails... By the way, I am using MySQL, and the DataBase is created by Prestashop, just in case that information is useful...