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 98 posts 473 karma points
    Mar 20, 2014 @ 16:59
    Gar├░ar ├×orsteinsson
    1

    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 :

            [Column("values")]

            [NullSetting]

            [MaxLength]

            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:

    https://github.com/umbraco/Umbraco-CMS/tree/7.1.0/src/Umbraco.Core/Persistence/DatabaseAnnotations

  • Patrick van Kemenade 90 posts 306 karma points
    Apr 03, 2021 @ 10:51
    Patrick van Kemenade
    0

    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 90 posts 306 karma points
    Apr 03, 2021 @ 11:08
    Patrick van Kemenade
    0

    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:

    https://our.umbraco.com/forum/developers/extending-umbraco/66609-umbracocorepersistence-ntext-deprecated-nvarchar-max

  • Huw Reddick 538 posts 1728 karma points
    Apr 03, 2021 @ 16:13
  • Patrick van Kemenade 90 posts 306 karma points
    Apr 03, 2021 @ 16:46
    Patrick van Kemenade
    0

    Awesome, thanks Huw (and Jose of course).

Please Sign in or register to post replies

Write your reply to:

Draft