Copied to clipboard

Flag this post as spam?

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

  • Garðar Þorsteinsson 114 posts 556 karma points
    Mar 20, 2014 @ 16:59
    Gar├░ar ├×orsteinsson

    Code first create Nvarchar(Max)

    Hi all,

    I have been scratching my head all day on how to make Umbraco create a custom table from model on Application start.

    I got all the functions working but I cant seem to make it create a Nvarchar(Max) column.

    This is my Model column :




            public string values { get; set; }


    I know the MaxLength is more of an EF attribute and should not work, I found in the Umbraco core all the data attributes available and the only attribute that could change the length of the string is [Length(4000)] but I cant do [Length] to get Max. 

    Any ideas how this is done ?

    Link to all the attributes:

  • Patrick van Kemenade 101 posts 339 karma points
    Apr 03, 2021 @ 10:51
    Patrick van Kemenade

    Same here.

    Another very strange behaviour is that nullable types like string or double? get translated to non nullable types. Unless you explicitly tell for every column individually that this nullable column must translate to a nullable type in the DB.

    Bottom line be very carefull when using NPOCO to generate custom tables especially when used to entity framework or plain SQL, this one just works different and is less intuitive.

  • Patrick van Kemenade 101 posts 339 karma points
    Apr 03, 2021 @ 11:08
    Patrick van Kemenade

    Also [Length(4000)] seems to be the max length which can be specified which translate to nvarchar(4000), while a nvarchar(max) is 2GB in size.

    So think you have to run SQL to fix your table after creating it to have a text field with more then 4000 characters. This is the same "solution" people have come up with in this thread:

  • Huw Reddick 1770 posts 6157 karma points MVP c-trib
    Apr 03, 2021 @ 16:13
  • Patrick van Kemenade 101 posts 339 karma points
    Apr 03, 2021 @ 16:46
    Patrick van Kemenade

    Awesome, thanks Huw (and Jose of course).

Please Sign in or register to post replies

Write your reply to: