We have a table, that contains more then 1000000 records. How to remove this records without materialization? This code is too greedy for resources:

var res = session.Query.All<DataModel.GPSData>()
          .Where(d => d.StartDateTime < DateTime.Now);
foreach (var item in res)

Also looking on Compiled Query, but i can't find the way to use it, because documented example is'nt work any more in version 4.4.

asked Oct 18 '11 at 21:54

Dmitry%20F's gravatar image

Dmitry F

It's impossible for some situation, because logic, coded using constraight and associations can't be processed.

(Oct 18 '11 at 23:52) Dmitry F Dmitry%20F's gravatar image

Taiwan, thanks for pointing us to the trouble with compiled queries documentation. We'll fix this soon.

As for correct usage, try this:

var items = session.Query.Execute(qe => qe.All<MyEntity>());
foreach (var item in items) {
    // Doing some stuff
(Oct 19 '11 at 04:14) Dmitri Maximov Dmitri%20Maximov's gravatar image

One Answer:


var countDeleted = session.Query.All<DataModel.GPSData>()
      .Where(d => d.StartDateTime < DateTime.Now).Delete();
var countUpdated = session.Query.All<DataModel.GPSData>()
      .Where(d => d.StartDateTime < DateTime.Now).Update(d=>new DataModel.GPSData{Data=d.Data*2, Data1=5, Data2=d.Data3+"test"});

i will publish it in nuget soon. Limitations: reference fields in Update method are not supported, supports only mssql driver, compiled queries are not supported

answered Oct 19 '11 at 03:14

proff's gravatar image


edited Oct 19 '11 at 03:28



The NuGet package is ready for use. It can be installed via Visual Studio NuGet package manager, more info is here.

The package is called DataObjectsExtensions, it provides server-side batch DML operations. Current limitations: MS SQL Server only. Not supported yet: reference fields in Update method, compiled queries.

(Oct 20 '11 at 16:30) proff proff's gravatar image
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!
toggle preview

powered by OSQA