IQuery NHibernate - does it HAVE to be a list?
-
09-06-2019 - |
Question
Can I return it as an object if I am doing a
Select OneItem from Table Where OtherItem = "blah"?
Is there a better way to do this?
I am building a constructor to return an object based on its name rather than its ID.
Solution
query.UniqueResult<T>()
returns just one T
OTHER TIPS
If there's more than one potential result, then query.FirstResult()
might be better.
Or using LINQ you can have query.First()
, query.SingleOrDefault()
, query.Min(predicate)
etc...
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow