0

I wanted to change my code-first project to SQL Server Compact 4.0.

But I have a problem with following LINQ expression

db.Test.OrderBy(t => t.Name).ToList()

It throws the following error

Large object (ntext and image) cannot be used in ORDER BY clauses

Is there a way to tell code-first to create a nvarchar type for the Name field instead of the ntext type when creating the database?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Palmi
  • 2,381
  • 5
  • 28
  • 65
  • *"ntext, text, and image data types will be removed in a future version of Microsoft SQL Server. Avoid using these data types in new development work, and plan to modify applications that currently use them. Use nvarchar(max), varchar(max), and varbinary(max) instead. "* - [The MSDN](https://msdn.microsoft.com/en-us/library/ms187993.aspx) – Scott Chamberlain Jul 21 '15 at 20:52
  • @ScottChamberlain: that applies to the **full** versions of SQL Server - this is about SQL Server **Compact** which doesn't have `nvarchar(max)` support... – marc_s Jul 22 '15 at 05:01

1 Answers1

1

Yes. Decorate the Name property of your entity class with this attribute:

[Column(TypeName = "nvarchar(MAX)")]

That should do the trick.

HaukurHaf
  • 13,522
  • 5
  • 44
  • 59