Try our conversational search powered by Generative AI!

ContentType question

Vote:
 

Hi,

I have another quite basic question that I have some problem understanding. I thought I understood the concept with pages but ran into a thing that I realised that I didn't quite understood. Lets take a trivial example:

Lets create a Page type that is called MyPage:

[ContentType]
public class MyPage : EPiServer.Core.PageData
{
   [Display(GroupName = SystemTabNames.Content, Order = 310)]
   public virtual string Title { get; set; }

}

So this class inherits from PageData which in turn implements the interface IContent so it is considered content and can be persisted and retrieved through EPiserver's data access layer. So far so good. To the question:

1. What I don't understand is how the class ContentType in namespace EPiServer.DataAbstraction( from which PageType and BlockType is inherited ) come into play? Is that some class that gets generated based on my declared page types, in this case the class MyPage?

2. I read in the documentation a part that i quote here "During initialization EPiServer CMS will scan all binaries in the bin folder for .NET classes that inherits PageData as example below. For each of the found classes a page type is created and for all public properties on the .NET class a corresponding property on the page type will be created." This may be related to question 1. The page type that is created in the quoted text is that one of type ContentType or what is that? 

3. I got a bit confused by the word "page type", what is the correct usage of that? I was under the impression that the class I created above called MyPage was a "page type" but that may not be the case. What is the class MyPage called in the correct lingo? Is it a "page type" a "page" or something else?

 

 

#67992
Mar 14, 2013 14:28
Vote:
 

Hi Magepi!

1. The use of ContentType in your MyPage is just as an attribute that you decorate your class with so that EPiServer can find it during the scan discussed in question 2.

2. The page type the text describes what is created in the database. Your MyPage class is what I would call a Page Type Definition. The "page type" is what is in the database and what is shown in Admin mode

3. see 2. 

 

#68006
Mar 14, 2013 15:23
Vote:
 

Thanks for the answer!

I realised that my question1 was very poorly formulated. I know that there is a attribute in my example above, however that was not what I was referrring to in my question ( which wasn't very easy to understand unfortunately ). I was referring to class ContentType in namespace EPiServer.DataAbstraction rather than the attribute in EPiServer.DataAnnotations.

My question appeared when I read an article by Joel Abrahamsson ( http://joelabrahamsson.com/episerver-7-content-pages-and-blocks/ ), in here he has a picture of the new Content/data model in EPiserver 7. And in that one there is a connection between IContent and ContentType which I dont understand. I don't understand when the class ContentType ( and the classes PageType and BlockType which inherits from it ) comes into play. What is it used for? Is that some intermediary class between my declared "page type definition" and the one in the database?

#68010
Mar 14, 2013 15:42
Vote:
 

Well yes, it is just that. A intermediary class between your definition and the database. It adds all the "EPiServer CMS" specific properties to your page types. 

#68014
Mar 14, 2013 16:09
Vote:
 

Ok thanks, one last question then =)

When using MVC I can send in a "MyPage" as the model to a view. In the view I can use like:

@Html.PropertyFor(x => x.Title)

So then somewhere in EPiServer code there is some logic that maps x.Title ( that here points to the Title property in MyPage class ) to the intermediary class of type ContentType which has all the "EPiSserver CMS" specific properties? Because it works somehow, and I can see the data in the database connected to that property =) Is there some way I can see this with the help of decompilation or reflection or something? Would be nice to be able to see how it looks in code so that I can try to understand it fully.

 

 

#68015
Mar 14, 2013 16:47
Vote:
 

Well the theori is correct. Just in the case of Title it is not. The Title comes from your inheritance of PageData. But should you ask for the ACL (access control list) i.e check what access roles are set on the page then you would ask for a property defined on the ContentType class.

If you have Reflector or ISpy you can check the code in the dlls

You can also check the sdk (sdk.episerver.com)

#68022
Mar 14, 2013 17:14
Vote:
 

Thanks Petter for having patience with my questions =)

Do you know in which dll to look to find the generated classes of type ContentType? I guess the EPiServer framework generates the classes somehow after I have created a page type definition, controller and view and built the project. In my case there is a DLL file located in /Visual Studio 2012\Projects\TryingOut\TryingOut\bin named same as my project but I can't see any files in it that looks promising. Do you have an idea where those files would end up? Or are they only in-memory (if that is even possible)

#68024
Mar 14, 2013 17:42
Vote:
 

I'm glad I can help!

The classes are already generated by EPiServer. You get the functionality within your class since you are inheriting from PageData. The inheritance means that your class will have everything the PageData class has AND whatever more properties and methods you create in your class.

The class ContentType is as you said before in the EPiServer.DataAbstraction namespace so you would find this in the EPiServer.Data.dll and that dll can be found in c:\program files (x86)\episerver\framework\<YourEpiVersionHere>\bin.

The PageData class is found in the EPiServer.Core.dll and that can be found in c:\program files (x86)\episerver\cms\<YourEpiVersionHere>\bin.

Link to ContentType in the SDK:

http://world.episerver.com/Documentation/Class-library/?documentId=cms/7/765ce432-d8ca-04ed-19a5-6bb8d789e665

Link to PageData in the SDK:

http://world.episerver.com/Documentation/Class-library/?documentId=cms/7/b38e303b-a955-4dc6-4bd0-d954c4815ea2

 

 

#68032
Mar 14, 2013 21:03
Vote:
 

Thanks again Petter! 

I will start to say sorry if I ask something again that you have already answered but I think I may miss something crucial here but let me sum up the things I have asked and your answers here to see where the missing part is ( probably in my head =) )

1. I start by creating my own page type definition in code. Lets use the same as I wrote above:

[ContentType]
public class MyPage : EPiServer.Core.PageData
{
   [Display(GroupName = SystemTabNames.Content, Order = 310)]
   public virtual string Title { get; set; }

}

2. On this part I am a bit confused but something like this happens if I understand it correctly? During initialization EPiServer CMS will scan all binaries and for all classed inheriting PageData ( and possibly also need to have attribute [ContentData] ) a page type will be created. The page type is basically a database representation for my page type definition. So I guess there is a table created for the page type with a column for each property and other stuff needed. ( or however it is implemented in the database).

Now to the tricky part ( at least in my brain it seems ). There has to be a "connection" or "glue" between my page type definition ( MyPage ) and the parts in the database. Because the properties that I have defined in MyPage can't automatically be mapped to the corresponding database post. So if I understand it correctly it is here when class ContentType ( and PageType/BlockType which inherits from ContentType) comes into play. This part I don't really get. Does EPiServer framework generate an instance of ContentType for all my page type definitions and populates it with all properties, both my own and the ones inherited from PageData? Something like "new ContentType<MyPage>()" or "new ContentType(something_that_identifies_my_page_type_def)? It seems the framework has to create instances in some way because you can create new page types through the admin gui and then you dont even have a corresponding page type definition in code so something has to be created?

3. We talked earlier in the thread about when sending MyPage as the model to the view when using MVC. I quote a bit of your answer

"But should you ask for the ACL (access control list) i.e check what access roles are set on the page then you would ask for a property defined on the ContentType class".

I'm not sure I quite understand that part, the ACL property exist in both PageData and in ContentType. If I write like this in my view

@Html.PropertyFor(m => m.ACL) then m.ACL would refer to the ACL defined in PageData because my model inherits from that class. Or am I misunderstaning something here?

 

 

#68056
Edited, Mar 15, 2013 11:29
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.