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.
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.
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:
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
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.
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
Is this what you need? https://github.com/umbraco/Umbraco-CMS/pull/8031
Awesome, thanks Huw (and Jose of course).
is working on a reply...