classicavgfunction.cs

来自「NHibernate NET开发者所需的」· CS 代码 · 共 51 行

CS
51
字号
using System;
using System.Data;
using NHibernate.Engine;
using NHibernate.SqlTypes;
using NHibernate.Type;

namespace NHibernate.Dialect.Function
{
	/// <summary>
	/// Classic AVG sqlfunction that return types as it was done in Hibernate 3.1
	/// </summary>
	public class ClassicAvgFunction : ClassicAggregateFunction
	{
		public ClassicAvgFunction() : base("avg", false)
		{
		}

		public override IType ReturnType(IType columnType, IMapping mapping)
		{
			if (columnType == null)
			{
				throw new ArgumentNullException("columnType");
			}
			SqlType[] sqlTypes;
			try
			{
				sqlTypes = columnType.SqlTypes(mapping);
			}
			catch (MappingException me)
			{
				throw new QueryException(me);
			}

			if (sqlTypes.Length != 1)
			{
				throw new QueryException("multi-column type can not be in avg()");
			}

			SqlType sqlType = sqlTypes[0];

			if (sqlType.DbType == DbType.Int16 || sqlType.DbType == DbType.Int32 || sqlType.DbType == DbType.Int64)
			{
				return NHibernateUtil.Single;
			}
			else
			{
				return columnType;
			}
		}
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?