Er, based on the code below, isn't that what you'd expect? According to
my reading (with the assumptions that criteriaQuery is defined before
this code block and executed afterwards) this code does the following:
1. Checks to see if _searchCriteria.MessageType is populated
2. If so, checks to see if the value is a valid enum
value
3. If so, adds an appropriate condition
to criteriaQuery
If _searchCriteria.MessageType isn't populated, or if it's populated
with a value that's not valid for the enum, then no Restriction is added
to criteriaQuery so therefore it will return "everything" when executed.
Does the 2nd if statement need an 'else' clause?
/Pete
From: [email protected] [mailto:[email protected]] On
Behalf Of Heidel
Sent: 05 December 2013 13:28
To: [email protected]
Subject: [nhusers] NHibernate Criteria Filtering
I use this code to filter database records
if (!string.IsNullOrEmpty(_searchCriteria.MessageType))
{
if
(Enum.GetNames(typeof(AutotransferMessageType)).Any(name =>
name.Equals(_searchCriteria.MessageType)))
{
var messageType =
(AutotransferMessageType)
Enum.Parse(typeof(AutotransferMessageType),
_searchCriteria.MessageType, true);
criteriaQuery.Add(
Restrictions.Eq(
"AutotransferInputRecord." +
AutotransferLogSearchCriteria.MessageTypePropertyName,
messageType));
}
}
AutotransferMessageType is enumerable type
public enum AutotransferMessageType
{
[DisplayName("MT202")]
[DatabaseName("MT202")]
MT202,
[DisplayName("MT210")]
[DatabaseName("MT210")]
MT210,
//...
}
I cant understand what's wrong with my code, filter outputs the right
results when I enter MT202 or any other fully matching value, but if I
input any value (not fully matching), filter outputs the all results
from DB without any filtering.
--
You received this message because you are subscribed to the Google
Groups "nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/nhusers.
For more options, visit https://groups.google.com/groups/opt_out.
--
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/nhusers.
For more options, visit https://groups.google.com/groups/opt_out.