Today I got into a situation where the field in our previous db, which should never be empty ... was empty.
I am using NHibernate 3.2 for this database, and queries that are affected are recorded in QueryOver.
My current request is
return Session .QueryOver<FacilityGroup>() .Where(fg => fg.Owner.Id == Token.OwnerId && fg.UserName == Token.UserName) .OrderBy(fg => fg.Code).Asc .TransformUsing(Transformers.DistinctRootEntity);
I want this to be:
return Session .QueryOver<FacilityGroup>() .Where(fg => fg.Owner.Id == Token.OwnerId && fg.UserName == Token.UserName && !string.IsNullOrEmpty(fg.Code)) .OrderBy(fg => fg.Code).Asc .TransformUsing(Transformers.DistinctRootEntity);
When I try to do this, I get the exception "Unrecognized method call: System.String: Boolean IsNullOrEmpty (System.String)"
So NHibernate cannot translate string.IsNullOrEmpty. Fair. However, when I try to do this
return Session .QueryOver<FacilityGroup>() .Where(fg => fg.Owner.Id == Token.OwnerId && fg.UserName == Token.UserName && !(fg.Code == null || fg.Code.Trim() == "" )) .OrderBy(fg => fg.Code).Asc .TransformUsing(Transformers.DistinctRootEntity);
I get an InvalidOperationException variable "fg" of type "Domain.Entities.FacilityGroup", which refers to the scope "", but it is not defined "
Any thoughts?
source share