Content inheritance custom modules

Posted by Community Admin on 03-Aug-2018 18:06

Content inheritance custom modules

All Replies

Posted by Community Admin on 18-Jun-2011 00:00

Hi

I am creating variety of custom content modules for Sitefinity 4.1SP1 and looking for way to implement module content item inherited from abstract class inherited from Telerik.Sitefinity.GenericContent.Model.Content class

What I mean:
I have AbstractItem class with some properties the same for all modules', inherited from Content
I have ConcreteClass class inherited from Abstract Item with new properties

Please tell is it possible in SF4 to use such hierarchies?  How FluentMappings should be configuring to make it work?

Thank you!

[Persistent(IdentityField = "contentId")]
public class ConcreteClass: AbstractItem
        [DataMember]
        public string NewConcreteProp get; set;

[Persistent]
public class AbstractItem: Telerik.Sitefinity.GenericContent.Model.Content
        [DataMember]
        public string MyCoolSharedProperty get; set;

Posted by Community Admin on 20-Jun-2011 00:00

Hello Kronos,

You can donwnload our SDK where you will find a complete sample of content based module.

Kind regards,
Ivan Dimitrov
the Telerik team

Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 20-Jun-2011 00:00

Hi Ivan

I am using Products module from SDK as reference.

I have added MyBaseClass class:

using Telerik.Sitefinity.GenericContent.Model;
 
namespace ProductCatalogSample.Model
    public class MyBaseClass : Content
    
    

and changed definition of ProductItem class:
[DataContract(Namespace = "http://sitefinity.com/samples/productcatalogue", Name = "ProductItem")]
    [ManagerType("ProductCatalogSample.Data.ProductsManager, ProductCatalogSample")]
    [Persistent(IdentityField = "contentId")]
    public class ProductItem : MyBaseClass, IApprovalWorkflowItem, ISecuredObject, ILocatable, ISitefinityCustomTypeSerialization
    
...

it is inherited from MyBaseClass instead of Content. So inheritance is ProductItem -> MyBaseClass -> Content now.
I haven't changed any other code.

The exception is occured now:

Server Error in '/' Application.

Mapping for field 'id' is specified in the file 'config', but the field is not present in the class 'ProductCatalogSample.Model.ProductItem'. --> FromMetadataContainer/namespace[ProductCatalogSample.Model]/class[ProductItem]/field[id]

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: Telerik.OpenAccess.Exceptions.MetadataException: Mapping for field 'id' is specified in the file 'config', but the field is not present in the class 'ProductCatalogSample.Model.ProductItem'. --> FromMetadataContainer/namespace[ProductCatalogSample.Model]/class[ProductItem]/field[id]

Source Error:

Line 32:         /// </summary>
Line 33:         /// <param name="providerName">Name of the provider.</param>
Line 34:         public ProductsManager(string providerName)
Line 35:             : base(providerName)
Line 36:         

Source File: c:\Work\Josh\Test\Products\Data\ProductsManager.cs    Line: 34

Stack Trace:

[MetadataException: Mapping for field 'id' is specified in the file 'config', but the field is not present in the class 'ProductCatalogSample.Model.ProductItem'. --> FromMetadataContainer/namespace[ProductCatalogSample.Model]/class[ProductItem]/field[id]]
   Telerik.Sitefinity.Data.OA.OpenAccessConnection.UpgradeDatabase(Database database) +309
   Telerik.Sitefinity.Data.OA.OpenAccessConnection.UpdateMetadata(MetadataSource metadataSource, String moduleName, List`1 dynamicTypesToRegister, IOpenAccessUpgradableProvider upgradable) +2157

[Exception: Unable to upgrade database schema metadataSource provided by 'ProductCatalogSample.Data.Implementation.OpenAccessProvider': Mapping for field 'id' is specified in the file 'config', but the field is not present in the class 'ProductCatalogSample.Model.ProductItem'. --> FromMetadataContainer/namespace[ProductCatalogSample.Model]/class[ProductItem]/field[id]]
   DynamicModule.ns.Wrapped_OpenAccessProvider_b93524d88708452e9b8b88599a212975.Initialize(String providerName, NameValueCollection config, Type managerType) +405
   Telerik.Sitefinity.Data.ManagerBase`1.InstantiateProvider(IDataProviderSettings providerSettings, Type providerType, ExceptionPolicyName policy, ManagerBase`1 manager) +2211
   Telerik.Sitefinity.Data.ManagerBase`1.InstantiateProvider(IDataProviderSettings providerSettings, ExceptionPolicyName policy, ManagerBase`1 manager) +74
   Telerik.Sitefinity.Data.ManagerBase`1.SetProvider(String providerName, String transactionName) +214
   ProductCatalogSample.Data.ProductsManager..ctor(String providerName) in c:\Work\Josh\Test\Products\Data\ProductsManager.cs:34
   BuildUp_ProductCatalogSample.Data.ProductsManager(IBuilderContext ) +335
   Telerik.Microsoft.Practices.ObjectBuilder2.BuildPlanStrategy.PreBuildUp(IBuilderContext context) +304
   Telerik.Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context) +434
   Telerik.Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object existing, String name, IEnumerable`1 resolverOverrides) +440

[ResolutionFailedException: Resolution of the dependency failed, type = "ProductCatalogSample.Data.ProductsManager", name = "OpenAccessDataProvider".
Exception occurred while: Calling constructor ProductCatalogSample.Data.ProductsManager(System.String providerName).
Exception is: Exception - Unable to upgrade database schema metadataSource provided by 'ProductCatalogSample.Data.Implementation.OpenAccessProvider': Mapping for field 'id' is specified in the file 'config', but the field is not present in the class 'ProductCatalogSample.Model.ProductItem'. --> FromMetadataContainer/namespace[ProductCatalogSample.Model]/class[ProductItem]/field[id]
-----------------------------------------------
At the time of the exception, the container was:

  Resolving ProductCatalogSample.Data.ProductsManager,OpenAccessDataProvider
  Calling constructor ProductCatalogSample.Data.ProductsManager(System.String providerName)
]
   Telerik.Sitefinity.Data.ManagerBase.GetManager(Type managerType, String providerName) +276
   Telerik.Sitefinity.Web.UI.ContentUI.ContentView.ResolveContentManager() +303
   Telerik.Sitefinity.Web.UI.ContentUI.ContentView.ResolveDetailItem() +128
   Telerik.Sitefinity.Web.UI.ContentUI.ContentView.CreateChildControls() +50
   System.Web.UI.Control.EnsureChildControls() +182
   System.Web.UI.Control.PreRenderRecursiveInternal() +60
   System.Web.UI.Control.PreRenderRecursiveInternal() +222
   System.Web.UI.Control.PreRenderRecursiveInternal() +222
   System.Web.UI.Control.PreRenderRecursiveInternal() +222
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4201

Please tell how should I change mappings to make my sample work?

I was investigating SDK and documentation for 2 days to find solution and didn't find it, Found Fluent mapping inheritance articles http://www.telerik.com/help/openaccess-orm/fluent-mapping-inheritance-horizontal.html
but I tried to write mappings as in article and have no success with my problem.

I appreciate your help

Posted by Community Admin on 23-Jun-2011 00:00

Hello Kronos,

We really need to see the rest of your code - how you map your MyBaseClass etc.. Can you attach your whole module source code, i cannot currently come up with an idea what is breaking.

Greetings,
Nikolay Datchev
the Telerik team

Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 25-Jun-2011 00:00

Hi

I haven't added any mappings. I got Products sample from SDK and made only changes I have published in prev post.
Really I don't need to have MyBaseClass in database, it should be just class where some shared methods and data will be presented to minimize code (I need to create a lot of modules).

If I inherit ProductItem from Content it works, but when I inherit from MyBaseClass that inherited from Content it crashes, I don't understand why and what should I do to fix it. I don't need MyBaseClass mapped to DB.

Mappings from Products SDK sample:

public class ProductsFluentMapping : OpenAccessFluentMappingBase
    
 
        public ProductsFluentMapping(IDatabaseMappingContext context)
            : base(context)
        
 
 
        public override IList<MappingConfiguration> GetMapping()
        
            var mappings = new List<MappingConfiguration>();
            MapItem(mappings);
            MapUrlData(mappings);
            return mappings;
        
 
        private void MapItem(IList<MappingConfiguration> mappings)
        
            var itemMapping = new MappingConfiguration<ProductItem>();
            itemMapping.HasProperty(p => p.Id).IsIdentity();
            itemMapping.MapType(p => new ).ToTable("custom_products");
            itemMapping.HasProperty(p => p.Price);
            itemMapping.HasProperty(p => p.QuantityInStock);
            itemMapping.HasAssociation<Telerik.Sitefinity.Security.Model.Permission>(p => p.Permissions);
            itemMapping.HasProperty(p => p.InheritsPermissions);
            itemMapping.HasAssociation<Telerik.Sitefinity.Security.Model.PermissionsInheritanceMap>(p => p.PermissionChildren);
            itemMapping.HasProperty(p => p.CanInheritPermissions);
            itemMapping.HasAssociation(p => p.Urls).WithOppositeMember("parent","Parent").ToColumn("content_id").IsDependent().IsManaged();
            itemMapping.HasAssociation<Telerik.Sitefinity.Workflow.Model.Tracking.ApprovalTrackingRecordMap>(p => p.ApprovalTrackingRecordMap);
            mappings.Add(itemMapping);
        
 
        private void MapUrlData(IList<MappingConfiguration> mappings)
        
            var urlDataMapping = new MappingConfiguration<ProductItemUrlData>();
            urlDataMapping.MapType(p => new ).Inheritance(InheritanceStrategy.Flat).ToTable("sf_url_data");
            mappings.Add(urlDataMapping);
        
    

Posted by Community Admin on 29-Jun-2011 00:00

Hi Kronos,
We actually have such hierarchy with our media content classes, the base abstract class is MediaContent and the inheritors are Image, Video,Document. I am attaching the mddel classes and the fluent mapping classes of the Libraries module. So check out the MediaContent.cs and the
MapMediaContent methods and say MapImage methods in LibrariesFluentMapping.cs. Note that this inheritance hierarchy is flat , e.g. MediaContent abstract class maps to a table called "sf_media_content" , all the inerited classes map to the same table, but only add additional columns which are specific for thei needs. For example Image adds the Width and Height column. The base Content class has horizontal inheritnace strategy - which means that all inheritors of this class have different tables, so the News, Events ,BlogPosts.. are actually in different tables, althouigh they are all Content based. MediaContent is also in a new table, but since it's inheritance strategy is flat - the inheritors of MediaContent are saved in the same "sf_media_content" table.

Nikolay Datchev
the Telerik team
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

This thread is closed