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 826 posts 1269 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

     

  • Comment author was deleted

    Dec 21, 2012 @ 12:22

    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 826 posts 1269 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[]

  • Comment author was deleted

    Dec 21, 2012 @ 12:32

    No

    publicstringMessage{get;set;}

    becomes

    public List<string>Message{get;set;}
  • Martin Griffiths 826 posts 1269 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."}

  • Comment author was deleted

    Dec 21, 2012 @ 12:55

    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 826 posts 1269 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

  • Comment author was deleted

    Dec 21, 2012 @ 13:03

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

  • Comment author was deleted

    Dec 21, 2012 @ 13:04

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

  • Martin Griffiths 826 posts 1269 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.

Please Sign in or register to post replies

Write your reply to:

Draft