Content inheritance custom modules
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
;
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
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
[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
...
|
|
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
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);
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