public string CreateViewCodeSnippet(PolymorphicInfo conceptInfo)
        {
            // Column names list (@columnList) is separated from the create query (@sql)
            // to be used in subqueryes, to make sure that the order of columns is the same
            // in all the subqueries. This is necessary for UNION ALL.

            return(string.Format(
                       @"
DECLARE @columnList NVARCHAR(MAX);
SET @columnList = N'{2}';

DECLARE @sql NVARCHAR(MAX);
SET @sql = N'CREATE VIEW {0}.{1}
AS
SELECT
    ID = CONVERT(UNIQUEIDENTIFIER, NULL){3}
WHERE
    0=1
{4}';


PRINT @sql;
EXEC (@sql);
",
                       conceptInfo.Module.Name,
                       conceptInfo.Name,
                       PolymorphicPropertyNameTag.Evaluate(this),
                       PolymorphicPropertyInitializationTag.Evaluate(this),
                       SubtypeQueryTag.Evaluate(this)));
        }
 public PolymorphicUnionViewInfo(PolymorphicInfo conceptInfo)
 {
     this.Module    = conceptInfo.Module;
     this.Name      = conceptInfo.Name;
     this.CreateSql = CreateViewCodeSnippet(conceptInfo);
     this.RemoveSql = RemoveViewCodeSnippet(conceptInfo);
 }
        private void AddPolymorphicImplementations(List <Tuple <DataStructureInfo, string> > computationDependencies, PolymorphicInfo polymorphic, IDslModel existingConcepts, IConceptInfo errorContext)
        {
            var implementations = existingConcepts.FindByReference <IsSubtypeOfInfo>(imp => imp.Supertype, polymorphic);
            var unsupported     = implementations.Where(imp => !(imp.Subtype is IWritableOrmDataStructure)).FirstOrDefault();

            if (unsupported != null)
            {
                throw new DslSyntaxException(errorContext, $"The referenced '{polymorphic.GetUserDescription()}' is not supported"
                                             + $" because it contains a non-writable implementation '{unsupported.Subtype.GetUserDescription()}'."
                                             + $" Please use ChangesOnChangedItems instead, to manually set the computation's dependencies.");
            }

            computationDependencies.AddRange(implementations.Select(imp => Tuple.Create(imp.Subtype,
                                                                                        IsSubtypeOfMacro.GetComputeHashIdSelector(imp))));
        }
 public string RemoveViewCodeSnippet(PolymorphicInfo conceptInfo)
 {
     return(string.Format("DROP VIEW {0}.{1};", conceptInfo.Module.Name, conceptInfo.Name));
 }