Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Martin Griffiths 791 posts 1189 karma points c-trib
    Dec 21, 2012 @ 12:13
    Martin Griffiths
    0

    CodeFirst error on CheckBoxList prevalues

    Hi Tim

    I think I've found another CodeFirst problem, here's my code...

    [Field(FormPages.Registration, FormFieldsets.Details,
                Type = typeof(CheckBoxList), Prevalues=new string[]{"Yes, I agree"}, Caption="Please tick this box if we may record your email address to contact you in the future regarding your benefits" )]
            public string Message { get; set; }

    It returns this...

    Object of type 'System.Collections.Generic.List`1[System.String]' cannot be converted to type 'System.String'.

    Please save my bacon!

    Martin

     

  • Tim Geyssens 6562 posts 15373 karma points MVP 2x c-trib
    Dec 21, 2012 @ 12:22
    Tim Geyssens
    0

    Hi Martin,

    Change the type of your property from string to List<string> that should do the trick (since a checkboxlist can return multiple items)

  • Martin Griffiths 791 posts 1189 karma points c-trib
    Dec 21, 2012 @ 12:27
    Martin Griffiths
    0

    Hi Tim

    What like this?

    Prevalues = new List<string>

    Prevalues will only accept a string array, string[]

  • Tim Geyssens 6562 posts 15373 karma points MVP 2x c-trib
    Dec 21, 2012 @ 12:32
    Tim Geyssens
    0

    No

    publicstringMessage{get;set;}

    becomes

    public List<string>Message{get;set;}
  • Martin Griffiths 791 posts 1189 karma points c-trib
    Dec 21, 2012 @ 12:50
    Martin Griffiths
    0

    Hi Tim

    That did the trick except that I now get this on submission of the form! It's pretty hardcore!

    inner exception

    {"Violation of PRIMARY KEY constraint 'PK_UFRecordDataString'. Cannot insert duplicate key in object 'dbo.UFRecordDataString'. The duplicate key value is (2dffd1f8-bf13-44d1-bc7e-5c5dfdeadd2b).\r\nThe statement has been terminated."}

  • Tim Geyssens 6562 posts 15373 karma points MVP 2x c-trib
    Dec 21, 2012 @ 12:55
    Tim Geyssens
    1

    Yeah was a bug that got into 3.0 and 3.0.1 , you'll need to update the db here is the script

    ALTER TABLE UFRecordDataString

    DROP CONSTRAINT PK_UFRecordDataString

    GO

  • Martin Griffiths 791 posts 1189 karma points c-trib
    Dec 21, 2012 @ 13:02
    Martin Griffiths
    0

    Hi Tim

    Executed the SQL successfully but i'm still getting the error, any ideas? I tickled the web.config.

    Martin

  • Tim Geyssens 6562 posts 15373 karma points MVP 2x c-trib
    Dec 21, 2012 @ 13:03
    Tim Geyssens
    0

    Are you sure it's executed on the correct db? Since if the constraint is gone it can't throw the error anymore...

  • Tim Geyssens 6562 posts 15373 karma points MVP 2x c-trib
    Dec 21, 2012 @ 13:04
    Tim Geyssens
    0

    If you have sql management studio you can double check and see if the table doesn't have the constraint anymore...

  • Martin Griffiths 791 posts 1189 karma points c-trib
    Dec 21, 2012 @ 15:36
    Martin Griffiths
    0

    Hi Tim

    Sorry I was being a plebb and made the change to staging instead of local. Oh well, both needed the change. 

    Thanks as always

    Merry Christmas to you!

    Martin.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies