public void TestConditionalProjectionWithConstantAndLikeExpression() { using (ISession session = this.OpenSession()) { var projection = (Projections.Conditional(Restrictions.Eq("SampleData", 1), Projections.Constant("Foo"), Projections.Constant("Bar"))); var likeExpression = new NHibernate.Criterion.LikeExpression(projection, "B", MatchMode.Start); var criteria1 = session.CreateCriteria<Model>() .Add(Restrictions.Eq("Id", 1)) .Add(likeExpression); var result1 = criteria1.UniqueResult<Model>(); var criteria2 = session.CreateCriteria<Model>() .Add(Restrictions.Eq("Id", 2)) .Add(likeExpression); var result2 = criteria2.UniqueResult<Model>(); Assert.IsNull(result1); Assert.IsNotNull(result2); } }
public async Task TestConditionalProjectionWithConstantAndLikeExpressionAsync() { // Fails on Firebird since it's unable to determine the type of the // case expression from the parameters. See http://tracker.firebirdsql.org/browse/CORE-1821. // I don't want to mess up the test with cast statements that the DB really shouldn't need // (or the NHibernate dialect should add them just when needed). using (ISession session = this.OpenSession()) { var projection = (Projections.Conditional(Restrictions.Eq("SampleData", 1), Projections.Constant("Foo"), Projections.Constant("Bar"))); var likeExpression = new NHibernate.Criterion.LikeExpression(projection, "B", MatchMode.Start); var criteria1 = session.CreateCriteria <Model>() .Add(Restrictions.Eq("Id", 1)) .Add(likeExpression); var result1 = await(criteria1.UniqueResultAsync <Model>()); var criteria2 = session.CreateCriteria <Model>() .Add(Restrictions.Eq("Id", 2)) .Add(likeExpression); var result2 = await(criteria2.UniqueResultAsync <Model>()); Assert.IsNull(result1); Assert.IsNotNull(result2); } }
public void TestConditionalProjectionWithConstantAndLikeExpression() { // Fails on Firebird since it's unable to determine the type of the // case expression from the parameters. See http://tracker.firebirdsql.org/browse/CORE-1821. // I don't want to mess up the test with cast statements that the DB really shouldn't need // (or the NHibernate dialect should add them just when needed). using (ISession session = this.OpenSession()) { var projection = (Projections.Conditional(Restrictions.Eq("SampleData", 1), Projections.Constant("Foo"), Projections.Constant("Bar"))); var likeExpression = new NHibernate.Criterion.LikeExpression(projection, "B", MatchMode.Start); var criteria1 = session.CreateCriteria<Model>() .Add(Restrictions.Eq("Id", 1)) .Add(likeExpression); var result1 = criteria1.UniqueResult<Model>(); var criteria2 = session.CreateCriteria<Model>() .Add(Restrictions.Eq("Id", 2)) .Add(likeExpression); var result2 = criteria2.UniqueResult<Model>(); Assert.IsNull(result1); Assert.IsNotNull(result2); } }
public void TestConditionalProjectionWithConstantAndLikeExpression() { using (ISession session = this.OpenSession()) { var projection = (Projections.Conditional(Restrictions.Eq("SampleData", 1), Projections.Constant("Foo"), Projections.Constant("Bar"))); var likeExpression = new NHibernate.Criterion.LikeExpression(projection, "B", MatchMode.Start); var criteria1 = session.CreateCriteria <Model>() .Add(Restrictions.Eq("Id", 1)) .Add(likeExpression); var result1 = criteria1.UniqueResult <Model>(); var criteria2 = session.CreateCriteria <Model>() .Add(Restrictions.Eq("Id", 2)) .Add(likeExpression); var result2 = criteria2.UniqueResult <Model>(); Assert.IsNull(result1); Assert.IsNotNull(result2); } }
private bool GetZoomDataBySearch(string searchValue) { bool hasSearched = false; if (TextBoxZoomField != null && !String.IsNullOrEmpty(searchValue)) { if (!String.IsNullOrEmpty(ZoomConfig.SearchByField)) { PropertyInfo prop = ZoomConfig.TypeEntity.GetProperty(ZoomConfig.SearchByField); if (prop != null) { Type propFieldType = prop.PropertyType; if (typeof(KPActiveRecordBase<>).IsSubclassOfRawGeneric(ZoomConfig.TypeEntity)) { MethodInfo method = ZoomConfig.TypeEntity.GetMethodInheritance("SlicedFindAll", new Type[] { typeof(int), typeof(int), typeof(Order[]), typeof(ICriterion[]) }); object zoomSearchReturn = null; if (method != null) { object valueTyped = Convert.ChangeType(searchValue, propFieldType); ICriterion criterionSearch = null; if (valueTyped is String) criterionSearch = new LikeExpression(ZoomConfig.SearchByField, valueTyped.ToString(), MatchMode.Anywhere); else criterionSearch = Expression.Eq(ZoomConfig.SearchByField, valueTyped); ICriterion filter = null; Order order = null; if (ZoomConfig.KPCriterionFilterDelegate != null) filter = ZoomConfig.KPCriterionFilterDelegate(); if (ZoomConfig.KPOrderDelegate != null) order = ZoomConfig.KPOrderDelegate(); Conjunction conj = new Conjunction(); conj.Add(criterionSearch); if (filter != null) conj.Add(filter); zoomSearchReturn = method.Invoke(null, new object[] { 0, 2, order, new ICriterion[] { conj } }); } if (zoomSearchReturn != null) { if (((Array)zoomSearchReturn).Length == 1) { hasSearched = true; foreach (var item in (Array)zoomSearchReturn) { object returnID = item.GetType().GetProperty(ZoomConfig.FieldReturnId).GetValue(item, null); if (returnID != null) HiddenZoomIDField.Value = returnID.ToString(); if (!String.IsNullOrEmpty(ZoomConfig.DisplaySearchField)) { object returnSearch = item.GetType().GetProperty(ZoomConfig.DisplaySearchField).GetValue(item, null); if (returnSearch != null) TextBoxZoomField.Text = returnSearch.ToString(); } else { TextBoxZoomField.Text = HiddenZoomIDField.Value; } object labelText = item.GetType().GetProperty(ZoomConfig.FieldReturnText).GetValue(item, null); if (labelText != null) DescriptionZoomField.Text = labelText.ToString(); } } else if (((Array)zoomSearchReturn).Length > 1) { OpenZoomWindow(); } } } } } } return hasSearched; }