/// <summary> /// Returns property types inheritted by base document type. /// </summary> public IList <PropertyType> GetInheritedPropertyTypes(ContentDbContext context) { context.Entry(this).Reference(dt => dt.Base).Load(); if (this.Base == null) { return(new List <PropertyType>()); } else { return(this.Base.AllPropertyTypes(context)); } }
/// <summary> /// Returns property types of this document type including the inheritted property types. /// Items are ordered according to the hierarchy (property types of root first), then by DisplayOrder. /// </summary> public IList <PropertyType> AllPropertyTypes(ContentDbContext context) { // Collect all inherited properties: var allPropertyTypes = this.GetInheritedPropertyTypes(context).ToList(); // Then add owned properties one by one: context.Entry(this).Collection(dt => dt.OwnPropertyTypes).Load(); foreach (var item in this.OwnPropertyTypes.OrderBy(pt => pt.DisplayOrder).ThenBy(pt => pt.Name)) { // Remove overriden properties: allPropertyTypes.RemoveAll(pt => pt.Name == item.Name); // Add the property: allPropertyTypes.Add(item); } // Return result: return(allPropertyTypes); }
protected override void OnModelCreating(ModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); modelBuilder.Entity <Document>() .Property(d => d.State) .HasComputedColumnSql("CASE WHEN [DeletedOnUtc] IS NOT NULL THEN 'Deleted' WHEN [PublishedOnUtc] IS NOT NULL THEN 'Published' WHEN [PublicationRequestedOnUtc] IS NOT NULL THEN 'Published' ELSE 'New' END"); modelBuilder.Entity <Property>() .Property(p => p.Settings) .HasConversion( v => ContentDbContext.ToString(v), s => ContentDbContext.ToDictionary(s), new ValueComparer <Dictionary <string, string> >( (v1, v2) => String.Equals(ContentDbContext.ToString(v1), ContentDbContext.ToString(v2)), v => ContentDbContext.ToString(v).GetHashCode(), v => v.ToDictionary(p => p.Key, p => p.Value) ) ); }