Ara
Generic filters
Exact matches only
Filter by Custom Post Type
Ana Sayfa / ASP.NET / NHibernate 3.2 için FreeTextExpression

NHibernate 3.2 için FreeTextExpression

NHibernate 3.2 için FreeTextExpression

 

[Serializable] public class FreeTextExpression : AbstractCriterion
{
private readonly string _propertyName;
private readonly object _value;
private readonly IProjection _projection;

///

/// Initializes a new instance of the class.
///

///The projection. ///The value. public FreeTextExpression(IProjection projection, object value)
{
_projection = projection;
_value = value;
}

///

/// Initialize a new instance of the
/// class for a named Property and its value.
///

///The name of the Property in the class. ///The value for the Property. public FreeTextExpression(string propertyName, object value)
{
_propertyName = propertyName;
_value = value;
}

public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery, IDictionary<string, IFilter> enabledFilters)
{
var sqlBuilder = new SqlStringBuilder();
var columnNames = CriterionUtil.GetColumnNames(_propertyName, _projection, criteriaQuery, criteria, enabledFilters);

if (columnNames.Length != 1)
{
throw new HibernateException(“Contains may only be used with single-column properties”);
}

sqlBuilder.Add(“freetext(“)
.Add(columnNames[0])
.Add(“,”);

sqlBuilder.Add(criteriaQuery.NewQueryParameter(GetParameterTypedValue(criteria, criteriaQuery)).Single());
sqlBuilder.Add(“)”);

return sqlBuilder.ToSqlString();
}

public override TypedValue[] GetTypedValues(ICriteria criteria, ICriteriaQuery criteriaQuery)
{
var typedValues = new List();

if (_projection != null)
{
typedValues.AddRange(_projection.GetTypedValues(criteria, criteriaQuery));
}
typedValues.Add(GetParameterTypedValue(criteria, criteriaQuery));

return typedValues.ToArray();
}

public TypedValue GetParameterTypedValue(ICriteria criteria, ICriteriaQuery criteriaQuery)
{
var matchValue = _value.ToString();
if (_projection != null)
{
return CriterionUtil.GetTypedValues(criteriaQuery, criteria, _projection, null, matchValue).Single();
}
return new TypedValue(NHibernateUtil.String, _value.ToString(), EntityMode.Poco);
}

public override IProjection[] GetProjections()
{
if (_projection != null)
{
return new [] { _projection };
}
return null;
}

public override string ToString()
{
return ” freetext(” + (_projection ?? (object)_propertyName) + “,” + _value + “)”;
}
}


Ayrıca bknz.

NHibernate OrderBy Random QueryOver Desteği

NHibernate OrderBy Random QueryOver Desteği ve ayrıca nhibernate için FreeTextExpression makalemizi okuyunuz. NHibernate QueryOver Desteği Veritabanından rasgele …

Bir Cevap Yazın

E-posta hesabınız yayımlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir