Ejemplo n.º 1
0
		private string DiscriminatorFilterFragment(string alias)
		{
			if (NeedsDiscriminator)
			{
				InFragment frag = new InFragment();

				if (IsDiscriminatorFormula)
				{
					frag.SetFormula(alias, DiscriminatorFormulaTemplate);
				}
				else
				{
					frag.SetColumn(alias, DiscriminatorColumnName);
				}

				string[] subclasses = SubclassClosure;
				for (int i = 0; i < subclasses.Length; i++)
				{
					IQueryable queryable = (IQueryable)Factory.GetEntityPersister(subclasses[i]);
					if (!queryable.IsAbstract)
						frag.AddValue(queryable.DiscriminatorSQLValue);
				}

				StringBuilder buf = new StringBuilder(50).Append(" and ").Append(frag.ToFragmentString().ToString());

				return buf.ToString();
			}
			else
			{
				return string.Empty;
			}
		}
		private string DiscriminatorFilterFragment(string alias)
		{
			const string abstractClassWithNoSubclassExceptionMessageTemplate = 
@"The class {0} can't be instatiated and does not have mapped subclasses; 
possible solutions:
- don't map the abstract class
- map the its subclasses.";

			if (NeedsDiscriminator)
			{
				InFragment frag = new InFragment();

				if (IsDiscriminatorFormula)
				{
					frag.SetFormula(alias, DiscriminatorFormulaTemplate);
				}
				else
				{
					frag.SetColumn(alias, DiscriminatorColumnName);
				}

				string[] subclasses = SubclassClosure;
				int validValuesForInFragment = 0;
				foreach (string t in subclasses)
				{
					var queryable = (IQueryable) Factory.GetEntityPersister(t);
					if (!queryable.IsAbstract)
					{
						frag.AddValue(queryable.DiscriminatorSQLValue);
						validValuesForInFragment++;
					}
				}
				if(validValuesForInFragment == 0)
				{
					throw new NotSupportedException(string.Format(abstractClassWithNoSubclassExceptionMessageTemplate, subclasses[0]));
				}
				StringBuilder buf = new StringBuilder(50).Append(" and ").Append(frag.ToFragmentString().ToString());

				return buf.ToString();
			}
			else
			{
				return string.Empty;
			}
		}
		private SqlString DiscriminatorWhereCondition(string alias)
		{
			InFragment frag = new InFragment()
				.SetColumn(alias, DiscriminatorColumnName);

			if (IsDiscriminatorFormula)
			{
				frag.SetFormula(alias, DiscriminatorFormulaTemplate);
			}
			else
			{
				frag.SetColumn(alias, DiscriminatorColumnName);
			}

			System.Type[] subclasses = SubclassClosure;
			for (int i = 0; i < subclasses.Length; i++)
			{
				IQueryable queryable = (IQueryable) Factory.GetEntityPersister(subclasses[i]);
				frag.AddValue(queryable.DiscriminatorSQLValue);
			}

			return frag.ToFragmentString();
		}