How to Insert data into database in Episerver ?

#180416 Jul 10, 2017 9:20
  • Member since: 2007

    Any data? Then I would recommend Entity Framework.

    #180430 Jul 10, 2017 13:03
  • Member since: 2010

    Hi,

    Not sure what you mean but to add data with episerver you need a Page Model. something like this

    [ContentType(DisplayName = "DefaultPage", GUID = "9dd28d67-02f1-4849-9cbc-726fb931ef81", Description = "")]
    public class DefaultPage : PageData
    {
    [CultureSpecific]
    [Display(
    Name = "Main body",
    Description = "The main body will be shown in the main content area of the page, using the XHTML-editor you can insert for example text, images and tables.",
    GroupName = SystemTabNames.Content,
    Order = 1)]
    public virtual XhtmlString MainBody { get; set; }
    }



    With this model it is possible to add a DefaultPage in episerver. This page has one field "Mainbody".

    If you need another field just add it to the model like this

    [ContentType(DisplayName = "DefaultPage", GUID = "9dd28d67-02f1-4849-9cbc-726fb931ef81", Description = "")]
    public class DefaultPage : PageData
    {
    [CultureSpecific]
    [Display(
    Name = "Main body",
    Description = "The main body will be shown in the main content area of the page, using the XHTML-editor you can insert for example text, images and tables.",
    GroupName = SystemTabNames.Content,
    Order = 1)]
    public virtual XhtmlString MainBody { get; set; }
    
    [CultureSpecific]
    [Display(Name = "Heading", Description = "", GroupName = SystemTabNames.Content, Order = 2)]
    public virtual string Heading { get; set; }
    }

    In editmode /EPiServer/Cms/ click  add (read the manual how to add pages)

    If you are new to episerver you should read this

    http://world.episerver.com/documentation/developer-guides/CMS/getting-started/

    #180445 Edited, Jul 11, 2017 8:31
  • Member since: 2010

    Hey, 

    Essentially, it depends on what kind of data you are trying to store.

    The options are:

    • IContent models, with Page examples Øyvind posted (you also have blocks, media, custom IContent as option)
    • DDS - Dynamic Data Store - for storing smaller number of items and without any complex relations.
    • EntityFramework or any other ORM, which Episerver doesn't restrict you from doing.

    First and second are explained well in the documentation, the third is not related to Episerver...

    Writing a usecase on what you need to store would help us give you a better answer.

    BR,
    Marija

    #180641 Jul 19, 2017 10:41