What's the difference between DetachedCriteria and ICriteria
Asked Answered
S

1

9

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?

Slaphappy answered 13/9, 2010 at 20:41 Comment(0)
T
11

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.

Terminology answered 13/9, 2010 at 20:43 Comment(3)
@kilonet Yes; seems bizarre. If you set a breakpoint on the second one and inspect the value of the local category variable, what is it?Terminology
yep, it was variable naming issueSlaphappy
DetachedCriteria is pretty cool if you work with generic data access layerOutwards

© 2022 - 2024 — McMap. All rights reserved.