예제 #1
0
        public IEnumerable <IConceptInfo> CreateNewConcepts(PolymorphicInfo conceptInfo, IDslModel existingConcepts)
        {
            var newConcepts = new List <IConceptInfo>();

            // Create a supertype SQL view - union of subtypes:

            newConcepts.Add(new PolymorphicUnionViewInfo(conceptInfo));

            // Create a subtype name property:

            var subtypeString = new ShortStringPropertyInfo {
                DataStructure = conceptInfo, Name = "Subtype"
            };

            newConcepts.Add(subtypeString);
            _conceptMetadata.Set(subtypeString, PolymorphicPropertyInfo.IsPolymorphicSystemProperty, true);
            newConcepts.Add(new PolymorphicPropertyInfo {
                Property = subtypeString
            });                                                                        // Minor optimization to reduce the number of macro evaluations.

            // Mark polymorphic properties:

            newConcepts.AddRange(existingConcepts
                                 .FindByReference <PropertyInfo>(p => p.DataStructure, conceptInfo)
                                 .Select(p => new PolymorphicPropertyInfo {
                Property = p
            }));

            // Automatically materialize the polymorphic entity if it is referenced or extended, so the polymorphic can be used in FK constraint:

            if (existingConcepts.FindByType <ReferencePropertyInfo>().Where(r => r.Referenced == conceptInfo && r.DataStructure is EntityInfo).Any() ||
                existingConcepts.FindByType <UniqueReferenceInfo>().Where(e => e.Base == conceptInfo && e.Extension is EntityInfo).Any())
            {
                newConcepts.Add(new PolymorphicMaterializedInfo {
                    Polymorphic = conceptInfo
                });
            }

            // Optimized filter by subtype allows better SQL server optimization of the execution plan:

            newConcepts.Add(new FilterByInfo
            {
                Source     = conceptInfo,
                Parameter  = "Rhetos.Dom.DefaultConcepts.FilterSubtype",
                Expression = @"(repository, parameter) =>
                {{
                    Expression<Func<Common.Queryable." + conceptInfo.Module.Name + @"_" + conceptInfo.Name + @", bool>> filterExpression = null;
                    parameter.ImplementationName = parameter.ImplementationName ?? """";
                    " + SetFilterExpressionTag.Evaluate(conceptInfo) + @"
                    if (filterExpression == null)
                        throw new Rhetos.ClientException(string.Format(""Invalid subtype name or implementation name provided: '{0}', '{1}'."",
                            parameter.Subtype, parameter.ImplementationName));
                    return Filter(Query().Where(filterExpression), parameter.Ids).ToSimple().ToArray();
                }}"
            });

            return(newConcepts);
        }
예제 #2
0
 public static bool IsSupported(ShortStringPropertyInfo property)
 {
     return property.DataStructure is EntityInfo;
 }