Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between DetachedCriteria and ICriteria

These classes have some similar methods but seem to work slightly different.

What's the difference between them and when should I use each of them?

like image 932
kilonet Avatar asked Sep 13 '10 20:09

kilonet


1 Answers

Detached criteria can be built up without reference to an ISession. You can later take that criteria and apply it to an ISession to get an executable ICriteria.

Use ICriteria when you have a session.

Use DetachedCriteria when you're not sure against what session the query will be executed.

Note that DetachedCriteria does not implement ICriteria -- they are not interchangeable. You must always call detachedCriteria.GetExecutableCriteria(session) to get an ICriteria instance.

like image 109
Jay Avatar answered Oct 20 '22 16:10

Jay