The entities
variable just contains a reference to the table. You should materialize your data in scope of the context, so you could do smth like
IQueryable<M> entities = null;
List<M> realEntities = null;
using (var context = new DataContext("MySql", ConnectionString))
{
entities = context.GetTable<M>();
// materialize entities in scope of the context
realEntities = entities.ToList();
}
return realEntities;
Also you could perform some filtering before the materialization:
using (var context = new DataContext("MySql", ConnectionString))
{
entities = context.GetTable<M>();
// you can apply Where filter here, it won't trigger the materialization.
entities = entities.Where(e => e.Quantity > 50);
// what exactly happens there:
// 1. Data from the M table is filtered
// 2. The filtered data only is retrieved from the database
// and stored in the realEntities variable (materialized).
realEntities = entities.ToList();
}
There is a topic about materialization I recommend you to look into.