2

Can I use the SqlServer NTEXT data type in LightSwitch?

I know how to add extension business types, but they always subclass the existing LightSwitch base types. The LightSwitch base type 'String' maps to the SqlServer data type NVARCHAR which has a limit of 4000 characters (if I'm not mistaken).

I need more than 4000 characters!

  • But you can't do that in LightSwitch itself... – Paul ten Brink Sep 21 '11 at 14:05
  • I don't know Lightswitch, but if you're mapping a string of potentially long length, your backend column should be nvarchar(max) which does not have the 4000 char limitation. – Jeremy Holovacs Sep 21 '11 at 14:07
  • Thanks, Jeremy, that would work for a 'normal' table, but this table is controlled by LightSwitch, so the NVARCHAR(MAX) would be overwritten next time I publish my project. – Paul ten Brink Sep 21 '11 at 14:17
  • 1
    You do understnad that ntext is deprecated and should NOT be used in any new code. – HLGEM Sep 21 '11 at 14:20
  • Did not know that, HLGEM. What should I be using instead? – Paul ten Brink Sep 21 '11 at 14:22
  • 1
    Once again, you should be using `NVARCHAR(MAX)`. This article seems to have a workaround for the limitation in LightSwitch: http://lightswitchhelpwebsite.com/Blog/tabid/61/EntryId/48/Using-the-Telerik-Rich-Text-Editor-In-Visual-Studio-LightSwitch.aspx – Aaron Bertrand Sep 21 '11 at 14:25

2 Answers2

4

Paul -- Nvarchar(4000) is what lightswitch defaults, but you can change the properties of the field by clearing the maximum length field, which will change it to nvarchar(max). Nvarchar(max) can store about 2Gb (much, much more than 4000 characters!)

Chains
  • 12,541
  • 8
  • 45
  • 62
1

Since NTEXT is deprecated, in order to use the proper data type (NVARCHAR(MAX)) in LightSwitch, create the table in SQL Server and then attach to it as an external table from LightSwitch. Reference.

Aaron Bertrand
  • 272,866
  • 37
  • 466
  • 490