+1-888-365-2779
Try Now
More in this section

Forums / Sitefinity SDK / duplicate table name in custom module

duplicate table name in custom module

4 posts, 0 answered
  1. Bobby
    Bobby avatar
    2 posts
    Registered:
    30 May 2011
    31 May 2011
    Link to this post
    Hi,

    I am trying to mimick the FormsModule and it's drag & drop controls support. I do not which to extend the FormsModule but rather create a new custom module that fits my needs. I am in the process of creating the Model structure for my custom module. However, in doing so, I get the following error when the Tables for my model are being created.

    Telerik.OpenAccess.Exceptions.MetadataException: Using a duplicate table name attempted for table 'sf_object_data' of class 'Pintek.QuestionTemplates.Model.QuestionTemplateDraftControl'.
    There seems to be table mapping defined in class 'Pintek.QuestionTemplates.Model.QuestionTemplateControl' using the same name.
    You must explicitly specify a different table name for class 'Pintek.QuestionTemplates.Model.QuestionTemplateDraftControl'. Open the 'Forward Mapping' dialog from OpenAccess, select the class 'Pintek.QuestionTemplates.Model.QuestionTemplateDraftControl' and set the table name. This generates the needed db-table-name extension in the config file.

    I do not get the exception if I rename the table to sf_object_data2. I understand that Sitefinity creates the table before my module and it's throwing an error because I am referencing the same table, but I thought if my mapping is flat and my custom class is of type ObjectData, then I could store my custom object in the sf_object_data table. Am I missing something?

    Also, the same renaming would have to occur for the sf_presentation_data and sf_draft_pages. In addition, my custom classes inherit from PresentationData and DraftData respectively. What am I missing?

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Telerik.Sitefinity;
    using Telerik.Sitefinity.Model;
    using Telerik.OpenAccess.Metadata.Fluent;
    using Telerik.OpenAccess;
    using Telerik.OpenAccess.Metadata.Fluent.Advanced;
    using Telerik.Sitefinity.Security.Model;
    using System.Linq.Expressions;
    using System.Reflection;
      
    namespace Pintek.QuestionTemplates.Model
    {
        public class QuestionTemplatesFluentMapping : OpenAccessFluentMappingBase
        {
            public QuestionTemplatesFluentMapping(IDatabaseMappingContext context)
                : base(context)
            { }
      
            public override IList<MappingConfiguration> GetMapping()
            {
                IList<MappingConfiguration> mappings = new List<MappingConfiguration>();
      
                mappings.Add(GetQuestionTemplatePresentationMapping());
                mappings.Add(GetQuestionTemplateDraftMapping());
                mappings.Add(GetQuestionTemplateControlMapping());
                mappings.Add(GetQuestionTemplateDraftControlMapping());
                mappings.Add(GetQuestionTemplateDescriptionMapping());
               
                return mappings;
            }
      
            public MappingConfiguration<QuestionTemplatePresentation> GetQuestionTemplatePresentationMapping()
            {
                MappingConfiguration<QuestionTemplatePresentation> configuration = new MappingConfiguration<QuestionTemplatePresentation>();
      
                configuration.MapType(p => new { }).Inheritance(InheritanceStrategy.Flat).SetTableName("sf_presentation_data", base.Context);
                configuration.HasAssociation<QuestionTemplateDraft>(p => p.QuestionTemplate);
      
                return configuration;
            }
      
            private MappingConfiguration<QuestionTemplateDraft> GetQuestionTemplateDraftMapping()
            {
                MappingConfiguration<QuestionTemplateDraft> configuration = new MappingConfiguration<QuestionTemplateDraft>();
      
                configuration.MapType(p => new { }).Inheritance(InheritanceStrategy.Flat).SetTableName("sf_draft_pages", base.Context);
                configuration.HasProperty(p => p.SubmitRestriction).IsNullable();
                configuration.HasProperty(p => p.SubmitAction).IsNullable();
                configuration.HasProperty(p => p.QuestionTemplateLabelPlacement).IsNullable();
                configuration.HasProperty(p => p.Name).ToColumn("nme").IsText(base.Context, 0xff, false).IsNullable();
                configuration.HasAssociation<QuestionTemplateDraftControl>(p => p.Controls).WithOpposite(p => p.QuestionTemplate).IsManaged().IsDependent();
                configuration.HasProperty(p => p.RedirectPageUrl).IsNullable();
                configuration.HasProperty(p => p.CssClass).IsNullable();
                configuration.HasAssociation<QuestionTemplateDescription>(p => p.ParentTemplate).ToColumn("content_id");
                configuration.HasProperty(p => p.LastControlId).ToColumn("last_control_id3").IsNullable();
                configuration.HasAssociation<QuestionTemplatePresentation>(p => p.Presentation).WithOpposite(p => p.QuestionTemplate).ToColumn("id2").IsManaged().IsDependent();
                configuration.HasField<QuestionTemplateDraft>("isTempTemplate");
                configuration.HasIndex<QuestionTemplateDraft>(p => new { Name = p.Name }).WithName("sf_idx_QuestionTemplateName");
      
                return configuration;
            }
      
            private MappingConfiguration<QuestionTemplateControl> GetQuestionTemplateControlMapping()
            {
                MappingConfiguration<QuestionTemplateControl> configuration = new MappingConfiguration<QuestionTemplateControl>();
      
                configuration.MapType(p => new { }).Inheritance(InheritanceStrategy.Flat).SetTableName("sf_object_data", base.Context);
                configuration.HasProperty(p => p.Published).ToColumn("published").IsNullable();
                configuration.HasAssociation<QuestionTemplateDescription>(p => p.QuestionTemplateDescription).HasFieldName("questionTemplateDescription").ToColumn("content_id");
                configuration.HasIndex<QuestionTemplateControl>((p => new { QuestionTemplateDescription = p.QuestionTemplateDescription }))
                    .WithName("idx_sf_object_data_content_id");
      
                return configuration;
            }
      
            private MappingConfiguration<QuestionTemplateDraftControl> GetQuestionTemplateDraftControlMapping()
            {
                MappingConfiguration<QuestionTemplateDraftControl> configuration = new MappingConfiguration<QuestionTemplateDraftControl>();
                  
                configuration.MapType(p => new { }).Inheritance(InheritanceStrategy.Flat).SetTableName("sf_object_data", base.Context);
                configuration.HasAssociation<QuestionTemplateDraft>(p => p.QuestionTemplate).ToColumn("id3");
                configuration.HasProperty(p => p.Published).ToColumn("published2").IsNullable();
                configuration.HasIndex<QuestionTemplateDraftControl>(p => new { QuestionTemplate = p.QuestionTemplate })
                    .WithName("idx_sf_object_data_id3");
      
                return configuration;
            }
      
            private MappingConfiguration<QuestionTemplateDescription> GetQuestionTemplateDescriptionMapping()
            {
                MappingConfiguration<QuestionTemplateDescription> configuration = new MappingConfiguration<QuestionTemplateDescription>();
      
                configuration.MapType(p => new { }).WithConcurencyControl(OptimisticConcurrencyControlStrategy.Version).SetTableName("sf_question_template_description", base.Context);
                configuration.HasProperty(p => p.Owner).IsNullable();
                configuration.HasProperty(p => p.LastModifiedBy).IsNullable();
                configuration.HasProperty(p => p.OriginalContentId).IsNullable();
                configuration.HasProperty(p => p.SubmitRestriction).IsNotNullable().ToColumn("submit_restriction");
                configuration.HasProperty(p => p.SubmitAction).IsNotNullable().ToColumn("submit_action");
                configuration.HasProperty(p => p.QuestionTemplateLabelPlacement).IsNotNullable().ToColumn("question_label_placement");
                configuration.HasProperty(p => p.Id).IsIdentity().IsNotNullable();
                configuration.HasProperty(p => p.DateCreated).IsNullable();
                configuration.HasProperty(p => p.LastModified).IsNullable();
                configuration.HasProperty(p => p.Name).ToColumn("nme").IsNullable();
                configuration.HasAssociation<QuestionTemplateControl>(p => p.Controls).WithOpposite(p => p.QuestionTemplateDescription).ToColumn("content_id").IsManaged().IsDependent();
                configuration.HasProperty(p => p.RedirectPageUrl).IsNullable();
                configuration.HasProperty(p => p.CssClass).IsNullable();
                configuration.HasAssociation<QuestionTemplateDraft>(f => f.Drafts).WithOpposite(f => f.ParentTemplate).ToColumn("content_id").IsManaged().IsDependent().WithLoadBehavior(LoadBehavior.Eager);
                configuration.HasProperty(p => p.LockedBy).IsNullable();
                configuration.HasProperty(p => p.QuestionTemplateEntriesSeed).IsNotNullable();
                configuration.HasProperty(p => p.LastControlId).IsNotNullable();
                configuration.HasAssociation<QuestionTemplatePresentation>(p => p.Presentation).IsDependent();
                configuration.HasAssociation<Telerik.Sitefinity.Security.Model.Permission>(p => p.Permissions);
                configuration.HasProperty(p => p.InheritsPermissions).IsNotNullable();
                configuration.HasAssociation<PermissionsInheritanceMap>(p => p.PermissionChildren);
                configuration.HasProperty(p => p.CanInheritPermissions).IsNotNullable();
      
                return configuration;
            }
        }
    }


    Thanks in advance for you help


  2. Pavel Iliev
    Pavel Iliev avatar
    140 posts
    Registered:
    18 Jul 2016
    06 Jun 2011
    Link to this post
    Hello Bobby,

    I think that you are not using the latest SP for your module. I would advise you to use it since there are major changes in the way that open access mappings are done (config file is no more used).
    Also could you provide more information what exactly do you want to achieve with mimicking the forms module? I'd recommend not to try to copy it but rather to extend it with your own widgets which will be much more easier and less problematic for you.

    Regards,
    Pavel
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

  3. Bobby
    Bobby avatar
    2 posts
    Registered:
    30 May 2011
    06 Jun 2011
    Link to this post
    Hi Pavel,

    I believe I have the latest sitefinity version. I have Sitefinity 4.1 SP1 Version  4.1.1395.0. What I am trying to do is use the forms module as the basis for another module that is similar to forms but is used for another purpose. I would also like to keep the ability for my client to be able to use the forms module as is. That's why I did not extend the forms functionality. In addition, when you say that the app.config file is no longer used, do you mean that the app.config of the Sitefinity.Module assembly should not contain mapping information for Open Access ORM? If so, then my version of Sitefinity.Module, which is version 4.1.1395.0, has Open Access ORM mapping information. Is this correct? Also, assuming everything is fine in my development environment, can you suggest some steps that I can take to resolve this issue?

    Thanks for your help,
    Bobby
  4. Pavel Iliev
    Pavel Iliev avatar
    140 posts
    Registered:
    18 Jul 2016
    14 Jun 2011
    Link to this post
    Hello Bobby,

    I sent a reply to your support request regarding the same issue. For your convenience, here is the response from the ticket:

    Regarding the 2 modules - you can create them based on the "Content" type. This will give you the webservices and ability to reuse the widgets that are for news/events/etc content based modules. If you need some more specialized widgets you can create them too. Also if your module is based on Content you'll be able to reuse the current functionality for "custom fields". Those widgets can be easily added into forms or pages editor, in a separate section.

    Creation of generic meta type builder and especially reusing the page editor will be much more harder task. For somebody that is really deep into Sitefinity API it would take at least a week. I expect some problems there because of hardcoded logic related to pages/forms & templates.
    There is the option to create a custom UI for building those meta types, like this one here:
    Administration ->Feeds & notifications ->Create a feed
    Under description: "Change data structure"

    Anyway if you'll have a fiexed data model you can just create your types and then if needed those could be extended with custom fields.

    About the JSON with "Content" based types there is ContentServiceBase which is used for news/events/etc grids & detail views.


    Greetings,
    Pavel
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

4 posts, 0 answered